/nodejs-bs-paginate

Yet another paginate view helper for nodejs.

Primary LanguageJavaScript

Travisci

nodejs-bs-paginate

Yet another paginate view helper for nodejs.

Generate html twitter bootstrap pagination.

https://github.com/nettantra/nodejs-bs-paginate/raw/master/media/pagination.png

or json for another usage

{
    baseCssClass: 'space separated list of classes',
    options: { showFirstLast: true, showPrevNext: true, showStep: true },
    first: { cssclass: 'disable', href: '#', text: '««' },
    previous: { cssclass: 'disable', href: '#', text: '«' },
    step: [
        { ispageno: true, cssclass: 'active', href: '#', text: '1' },
        { ispageno: true, cssclass: '', href: '/unknowurl?pageno=2', text: '2' },
        { ispageno: true, cssclass: '', href: '/unknowurl?pageno=3', text: '3' },
        { ispageno: true, cssclass: '', href: '/unknowurl?pageno=4', text: '4' },
        { ispageno: true, cssclass: '', href: '/unknowurl?pageno=5', text: '5' },
        { ispageno: false, cssclass: 'disabled', href: '#', text: '…' },
        { ispageno: true, cssclass: '', href: '/unknowurl?pageno=99', text: '99' },
        { ispageno: true, cssclass: '', href: '/unknowurl?pageno=100', text: '100' }
    ],
    next: { cssclass: '', href: '/unknowurl?pageno=2', text: '»' },
    last: { cssclass: '', href: '/unknowurl?pageno=100', text: '»»' }
}

Install

npm :

  • Edit your package.json

  • Add

    "dependencies": {
        "nodejs-bs-paginate": "git://github.com/nettantra/nodejs-bs-paginate.git#master"
    },
    
  • Execute npm install

  • Add var paginate = require('nodejs-bs-paginate'); in your code

browser (backbone, derbyjs ...)

Add

<script src="/nodejs-bs-paginate/lib/index.js"></script>

Usage

Html output

console.log(paginate({totalItem:100, itemPerPage:10, currentPage:2, url:'/mybeautifulapp'}));

Json output

console.log(paginate({totalItem:100, itemPerPage:10, currentPage:2, url:'/mybeautifulapp', getJson:true }));

Options

name default description
baseCssClass '' classes for the ul element
totalItem 1000 total items
itemPerPage 10 items per page
currentPage 1 current selected page
url '/unknowurl' default link
params {} your personnal params add to link : if {aa:bb} => url?aa=bb
parampageno 'pageno' key name add to link : url?pageno=10
showPrevNext true show previous and next button
showFirstLast true show first and last button
showStep true show step page. Show or Hide [1][2][3][4]
hideDots false hide dots separator (if showStep = true) [1][2][...][99][100]
DotsMidSize 4 show X step before and after current page (if hideDots = false)
DotsEndSize 2 show X step after first and before end page (if hideDots = false)
dotText '&#8230;' text for dots separator (if hideDots = false)
firstText '&laquo;&laquo;' text for goto first page
prevText '&laquo;' text for goto previous page
nextText '&raquo;' text for goto next page
lastText '&raquo;&raquo;' text for goto last page
addSep '' add \n in html output (only for debug)
getJson false get only Json ( not generate Html )
setJson false consume json (nodejs-bs-paginate compatible) to generate html (not use getJson and setJson)

Licence

Code licensed under the GNU GENERAL PUBLIC LICENSE Version 3

Credits

Forked From: https://github.com/ami44/nodejs-yapaginate