Pagination for javascript/nodejs
npm install paginationPagination for javascript/nodejs

js
var pagination = require('pagination');
var paginator = pagination.create('search', {prelink:'/', current: 1, rowsPerPage: 200, totalResult: 10020});
console.log(paginator.render());
`
$3
This example show how to generate markup for twitter boostrap, see example/twitter.html for template rendering
`js
var pagination = require('pagination')var boostrapPaginator = new pagination.TemplatePaginator({
prelink:'/', current: 3, rowsPerPage: 200,
totalResult: 10020, slashSeparator: true,
template: function(result) {
var i, len, prelink;
var html = '
';
if(result.pageCount < 2) {
html += '
';
return html;
}
prelink = this.preparePreLink(result.prelink);
if(result.previous) {
html += '' + this.options.translator('PREVIOUS') + ' ';
}
if(result.range.length) {
for( i = 0, len = result.range.length; i < len; i++) {
if(result.range[i] === result.current) {
html += '' + result.range[i] + ' ';
} else {
html += '' + result.range[i] + ' ';
}
}
}
if(result.next) {
html += '' + this.options.translator('NEXT') + ' ';
}
html += '
$3
`js
var pagination = require('pagination');
var paginator = new pagination.SearchPaginator({prelink:'/', current: 10, rowsPerPage: 200, totalResult: 10020});
console.log(paginator.render());
// output (without newlines)
``html
`
$3
`js
var pagination = require('pagination');
var paginator = new pagination.SearchPaginator({prelink:'/', current: 3, rowsPerPage: 200, totalResult: 10020});
console.log(paginator.getPaginationData());// output
{ prelink: '/',
current: 3,
previous: 2,
next: 4,
first: 1,
last: 51,
range: [ 1, 2, 3, 4, 5 ],
fromResult: 401,
toResult: 600,
totalResult: 10020,
pageCount: 51 }
`
Pagination on client side
`html
`
You can browse example folder for more. Release folder contains all mimified versions for browser. To customize your need you can use ./bin/build.js -h
html += paginator.render();Classes
$3
* options See Options bellowSee also http://developer.yahoo.com/ypatterns/navigation/pagination/search.html
$3
* options See Options bellowSee also http://developer.yahoo.com/ypatterns/navigation/pagination/item.html
$3
* options See Options bellowThis class will render the markup as desired. The options must contains property "template"
It can be either a template string or a compiled template. The local variables available in the template are
*
prelink String
* preparedPreLink String
* current Integer
* previous Integer
* next Integer
* first Integer
* last Integer
* range Array
* fromResult Integer
* toResult Integer
* totalResult Integer
* pageCount Integer
* translations Object with properties NEXT, PREVIOUS, FIRST, LAST, CURRENT_PAGE_REPORTAPI
$3
Return an object contains data for rendering markup. See example above.$3
Set value to a single for option. See options section bellow$3
* prelink StringAppend page param to the link
$3
Return the rendered markup$3
* type String
* options Object see Options section bellowWrapper for create instance of classes above
$3
See pagination.TemplateEngine.compile bellow$3
* str Template string
* options object which can contains .open .close .cache and .idOptions
Object to pass to paginator classes (second argument when using create function)$3
Number of total items in result set
$3
Link to append the page-param$3
Number of items per page, default to 10$3
Number of links to create in page range, default to 5. This value will be ignored when using item pagination.$3
Indicate which page is the current one. Page always starts with 1.$3
To indicate if the result from CURRENT_PAGE_REPORT translation can be cached or not. Default is false.
The cache is global and will be the same for all instances which have specified translationCacheKey as bellow.$3
For supporting multiple versions of translation of CURRENT_PAGE_REPORT. It can use for multilanguages or different formats. Default is "en"$3
For translations of FIRST, NEXT, ... Simple example
`js
var translations = {
'PREVIOUS' : 'Voorgaand',
'NEXT' : 'Volgende',
'FIRST' : 'Eerst',
'LAST' : 'Laatste',
'CURRENT_PAGE_REPORT' : 'Resulten {FromResult} - {ToResult} van {TotalResult}'
};var item = new ItemPaginator({
prelink : '/',
pageLinks : 5,
current : 5,
totalResult : 100,
translator : function(str) {
return translations[str];
}
});
``