GithubHelp home page GithubHelp logo

duataud / react-pagination Goto Github PK

View Code? Open in Web Editor NEW

This project forked from miguelalarcos/react-pagination

0.0 2.0 0.0 120 KB

A simple pagination widget for React and FlowRouter.

JavaScript 25.98% CoffeeScript 74.02%

react-pagination's Introduction

react-pagination

A simple pagination widget for React and FlowRouter.

Example

You must install kadira:flow-router and tmeasday:publish-counts.

@limit = 2

@Demo = React.createClass
    mixins : [ReactMeteorData]
    getMeteorData: ->
        posts: posts.find({}, {limit: limit, sort: {createdAt: 1}}).fetch()
    render: ->
        <div>
            {for post in @data.posts
                <div>
                    <h2>{post.title}</h2>
                    <em>{moment(post.createdAt).format('DD-MM-YYYY')}</em>
                </div>
            }
            <ReactPagination.Pagination itemsPerPage=limit window=5  count='total_posts' />
        </div>
        
FlowRouter.route '/',
  name: 'home'
  subscriptions: (params, queryParams) ->
      page = parseInt(queryParams.page) or 0
      offset = page*limit
      this.register('postsWithSkip', Meteor.subscribe('postsWithSkip', offset, limit))
  action: (params, queryParams) ->
    Template.body.onRendered ->
      React.render <Demo />, document.getElementById('yield')        
.page-selected {
    text-decoration: underline;
}

.first-button, .minus-button, .page-button, .plus-button, .last-button {
    cursor: pointer;
}

server side:

Meteor.publish 'postsWithSkip', (skip, limit) ->
  Counts.publish(this, 'total_posts', posts.find())
  if skip < 0 then skip = 0
  options = {}
  options.skip = skip
  options.limit = limit
  if options.limit > 10 then options.limit = 10
  options.sort = {createdAt: 1}
  posts.find({}, options)

react-pagination's People

Contributors

miguelalarcos avatar

Watchers

James Cloos avatar Yamir avatar

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.