express-bootstrap-pagination
v1.0.0
Published
Express middlware for generate standard page navigation bar styled with Bootstrap 3
Downloads
6
Readme
Express Bootstrap Pagination
Express middlware for generate standard page navigation bar styled with Bootstrap 3.
Installation
npm install --save express-bootstrap-pagination
or
yarn add express-bootstrap-pagination
API
const pagination = require( 'express-bootstrap-pagination' );
app.use( pagination );
Now in the Express app.locals
added 2 functions:
pagination
urlWithQuery
Each function can be interpolated as string in the template engine.
pagination( currentPage, totalPages, options )
This function have two required arguments:
currentPage
{ number } - number of current pagetotalPages
{ number } - number of total pages
options
options
{ object } is optional argument.
round
{ number } - number of pages around the current page. Default: 4outer
{ number } - number of outer window pages (first and last pages). Default 2param
{ string } - name of param for query url. Default: 'page'query
{ string } - additional query string to url. Optionalclass
{ string } - additional CSS class name for main pagination container. Optionalstart
{ number } - start number for query string. Default: 1. Optional
urlWithQuery( query )
query
{ object } - object with query parameters and its values. For replace query.
Parameters with undefined
, null
and empty values will be removed from query.
Example
Template engine is pug2
//- Pagination
if ( totalPages > 1 )
!=pagination( currentPage, totalPages, { round: 2 } )
//- urlWithQuery
a( class='btn' href=urlWithQuery( { status: 'free' } ) ) Free
a( class='btn' href=urlWithQuery( { status: 'busy' } ) ) Busy
a( class='btn' href=urlWithQuery( { status: null } ) ) All