Giter VIP home page Giter VIP logo

ember-pagination's Introduction

DO NOT USE

Working project is at Ember-CLI-Pagination


Ember Pagination

Simple library to do ember pagination. Works with servers using the will_paginate API.

Including in your project

Just include dist/ember-pagination.js in your project after including Ember and Ember Data.

Ember Pagination is also available as an npm module

How to Use

Just change your adapter from DS.RESTAdapter to Em.PaginationAdapter

App.Store = DS.Store.extend
  revision: 11
  adapter: 'Em.PaginationAdapter'

For your controllers, you must define info about your controller in modelInfo for the pagination to work.

There are two ways to create your controller:

// 1. Extend from Em.PaginationController instead of Em.ArrayController
App.WidgetsController = Em.PaginationController.extend({
  modelInfo: {
    store: 'widget',
    class: App.Widget
  }
});

// OR

// 2. Extend from Em.ArrayController and include the Em.PaginationModule
App.WidgetsController = Em.ArrayController.extend(Em.PaginationModule,{
  modelInfo: {
    store: 'widget',
    class: App.Widget
  }
});

This adds the showMore action to the controller.

(If you are using Ember App Kit, import the model at the top of the page and use Widget instead of App.Widget)

In your template, put something like this to load the next page:

<a href="#" {{action showMore}}>Show More</a>

Example Rails Controller:

# App must include WillPaginate and ActiveModelSerializers
class PostsController < ApplicationController
  def index
    page = (params[:page] || 1).to_i
    @posts = Post.all.paginate(:page => page, :per_page => 5)
    render :json => @posts, :meta => {:total_pages => @posts.total_pages, :page => page}
  end
end

Server Format

Request: The page number is sent as the page query param, or omitted if page is 1. Response: Server returns page and total_pages values in the meta tag of the response

{
  "meta": {
    "total_pages": 3,
    "page": 1
  },

  "posts": [
    {"id": 1, "title": "Hello World", body: "More to Come"},
    ......
  ]
}

ember-pagination's People

Contributors

mharris717 avatar

Stargazers

Ali Jonathan Nabavi avatar hysios  avatar  avatar Daniel Georgiev avatar Greg Malcolm avatar Lawrence Gosset avatar Sven Hanssen avatar Cameron Woodmansee avatar  avatar Mario Andrés avatar  avatar  avatar Christopher Hopper avatar Andrew Sullivan avatar Isaak Mogetutu avatar Ronen avatar Gabor Babicz avatar Stefano Mancini avatar  avatar Antonio avatar feipinghuang avatar Jasson Cascante avatar Manuel Vidaurre avatar Evan Culver avatar Nathan Ward avatar

Watchers

 avatar

ember-pagination's Issues

Update code for ember1.0 and ember-data.beta1

Hi.

I'm just tring to update your code to let it work with ember 1.0 and ember-data beta1, but without success (I'm working with ember since few days ago).

Could you please release an updated version?

Then I didn't understand if it automatically updates the view with the new data.

Thanks for your help,

Stefano

Does not define Em.PaginationAdapter

The README says:

  • Just include dist/ember-pagination.js in your project after including Ember and Ember Data.
  • Just change your adapter from DS.RESTAdapter to Em.PaginationAdapter

But unless I've missed something, ember-pagination.js does not define Em.PaginationAdapter.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.