Pagino is a JavaScript class designed to handle pagination logic independently.
npm i pagino
import Pagino from 'pagino';
const pagino = new Pagino();
pagino.setCount(10);
pagino.setPage(1);
pagino.getPages();
/**
* ['first', 'previous', 1, 2, 3, 4, 5, 'end-ellipsis', 10, 'next', 'last']
*/
pagino.setPage(5);
pagino.getPages();
/**
* ['first', 'previous', 1,'start-ellipsis', 4, 5, 6, 'end-ellipsis', 10, 'next', 'last']
*/
You can chain multiple methods together
pagino
.setCount(10)
.setPage(1)
.getPages();
The following values are the default options
const pagino = new Pagino({
showFirst: true,
showPrevious: true,
showNext: true,
showLast: true,
page: 1,
count: undefined,
siblingCount: 1,
boundaryCount: 1,
});
Instead of using setPage
, you can use the next
, previous
, first
, and last
methods:
pagino.next();
pagino.previous();
pagino.first();
pagino.last();
You can listen for page
and count
changes
const pagino = new Pagino({
...
onChange: (page, count) => {
console.log(page, count)
},
...
});
import Pagino from 'https://raw.githubusercontent.com/pagino/pagino-js/main/src/index.ts';