A javascript pagination library.
This plugin makes it easier to implement pagination using three (3) DOM elements as page containers (e.g. divs). "onPagechange" event can be used to update the contents of the outdated container making sure that we always have content available for the immediate pages while keeping the memory usage to a minimum.
The idea behind this library is to keep the memory usage to a minimum at the cost of CPU power. So, we use three container divs to navigate through the pages while updating their content dynamically.
First implement your pagination containers and style them accordingly so you have one active div shown and two hidden, one on the left (or top) and one on the right (or bottom). Then initialise a xPagination object and use the next() / previous() methods to navigate through pages.
// initialise var pagination = new xPagination( $('container-left'), $('container-active'), $('container-right'), ); // handle the pagechange event pagination.addEvent( 'pagechange', function( element, page ){ // refresh outdated page content }); // navigate through the pages pagination.next(); pagination.previous();
Maybe a more useful example is to use the xPagination.JSON.mustache class which will load the outdated pages with JSON data and use Mustache template parser to convert each JSON data record into a DOM record.
pagination = new xPagination.JSON.mustache( $('container-left'), $('container-active'), $('container-right'), data, { records_per_page: 2 } );
var pagination = new xPagination([el_left, el_active, el_right[, options]]);
Fired upon a page change
onPagechange(element, page)
var pagination = new xPagination( $('container-left'), $('container-active'), $('container-right'), { onPagechange: function( element, page ) { // load content into the outdated page } } );
Attach container elements to an instance.
pagination.attach(el_left, el_active, el_right);
var pagination = new xPagination.JSON(el_left, el_active, el_right, obj_json[, options]);
Fired when a page is loaded (or request to be loaded)
onPageload(element, page)
Fired when the data source is exhausted and there is no more data to be loaded into pages.
onExhausted()
var pagination = new xPagination.JSON( $('container-left'), $('container-active'), $('container-right'), data, { records_per_page: 2, onPagechange: function( element, page ) { // load content into the outdated page } } );
xPagination.JSON.mustache updates the page content using JSON data and mustache templates.
var pagination = new xPagination.JSON.mustache(el_left, el_active, el_right, obj_json[, options]);
Fired when a page is appended with a record
onInject(element, data);
var pagination = new xPagination.JSON.mustache( $('container-left'), $('container-active'), $('container-right'), data, { records_per_page: 2 } );
A note on comments here: These comments are moderated. No comments will show up until they are approved. Comments that are not productive (i.e. inflammatory, rude, etc) will not be approved.
Found a bug in this plugin? Please report it this repository's Github Issues.
blog comments powered by Disqus