Giter Club home page Giter Club logo

paginate's Introduction

Paginate

Paginate is angular module that contains two major components. The paginate factory is a component for creating paginator controllers. The paginator controller is the brain and does all the magic. The UI component is just a nice looking html which is connected and uses the paginator controller underneath.

The paginator factory

The paginator factory is able to producte paginator controller with various configuration parameters. This means that the factory is flexible and easy for use in various scenarios.

This is the way you need to use the factory in order to create paginator controller:

var module = ng.module('MainApp', ['paginate']);

module.controller('MainCtrl', ['$scope', 'paginatorFactory', function($scope, paginatorFactory){
	$scope.paginator = paginatorFactory.createPaginator(config);
}]);

The config object

recordCount - The total number of records you need to paginate

pageSize - The number of records per page

pageSizes - List from which page size can be picked via drop-down

windowSize - The number of pages seen at any given time in the UI component

sizeChangable - Whether the drop-down for changing page size dynamically is on or off (true/false)

summaryTemplate - String representing the template for generating summary of the current paginator state. Possible keys that the paginator factory recognizes are:

  • {start} - The start record index for the current page
  • {end} - The end record index for the current page
  • {currentPage} - The current page
  • {recordCount} - The record count

onChange - Function that is executed whenever the paginator changes state. The function should expect (start, end, currentPage, pageSize). Where start and end are the indexes in the original records list where the paginator currently looks at.

The paginator controller methods

loagPage([pageNumber]) - Computes the state for the given page number, or the current page if the page number is not provided. After this call the onChange callback is executed with the new state parameters

loadPreviousPage() - Computes the state for the previous page relative to the current page

loadNextPage() - Computes the state for the next page relative to the current page

loadFirstPage() - Computes the state for the first page

loadLastPage() - Computes the state for the last page

summary() - Generates summary for the paginator state using the summary template. The summary template defaults to '{start} to {end} out of {recordCount}'.

The example

In the given example we use imaginary users list of 300 users, displaying them in table. You can check the index.html and main.js to see how the paginator is used, and also experiment with the config object to see different outcomes.

Notes

In order to test the example you need to run it through http server rooted at the folder of the projects so that the directive template is correctly resolved.

This example was tested with the help of the python http server module.

paginate's People

Contributors

mitevs avatar

Stargazers

 avatar  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.