Giter Club home page Giter Club logo

ngpaginator's Introduction

#ngPaginator

Angular Directive for Data Pagination. by Po Chen Lin

##How to Use

  1. Declare paginator directive in your module.

    angular.module('app',[])
    .directive('paginator',Paginator);
    function Paginator(){ ... }
  2. Declare startFrom filter in your module.

    .filter('startFrom',startFrom)
    function startFrom() { ... }
  3. In controller, create model for binding. (data, curPage, pageSize, pagerSize)

    // use controller as viewmodel or old fashion $scope for view
    this.data = data; // array of data
    this.curPage = 0; // current page. External function can change page with this
    this.pageSize = 10; // how many items per page
    this.pagerSize = 5; // how many pagers in paginator (odd number recommended)
  4. Create remote template for paginator (Customize for your own need)

    <button ng-disabled="curPage == 1" ng-click="prev()">Prev</button>
    <button ng-repeat="p in pagers()" ng-disabled="this.p == curPage" ng-click="goPage(this.p)">{{p}}</button>
    <button ng-disabled="curPage >= maxPage()" ng-click="next()">Next</button>
  5. In html view, you can use directive in controller scope like this.

    // element style 
    <paginator data="main.data" cur-page="main.curPage" page-size="main.pageSize" pager-size="main.pagerSize"></paginator>
    
    // ngRepeat for each page (where startFrom filter kickin)
    <ul>
    <li ng-repeat="p in main.data | startFrom:(main.curPage-1)*main.pageSize | limitTo:main.pageSize">{{p.name}} - {{p.email}}</li>
    </ul>
    
    // Attribute style
    <div data="main.data" cur-page="main.curPage" page-size="main.pageSize" pager-size="main.pagerSize" paginator></div>

for detail, check out the example code.

##License The MIT License (MIT)

ngpaginator's People

Watchers

James Cloos avatar Inno 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.