pagination-bar-generator
v0.4.0
Published
This library is used for generating pagination bar.
Downloads
27
Maintainers
Readme
pagination-bar-generator
This library is used for generating pagination bar.
Usage
import { Paginator } from "pagination-bar-generator";
const paginator = Paginator.builder(5).currentPage(1).buildPaginator();
let html = "";
for (const pageItem of paginator.paginate()) {
if (pageItem.isPrev()) {
html += `<li><a href="/page/${pageItem.pageNumber}">«</a></li>`;
} else if (pageItem.isPage()) {
html += `<li><a href="/page/${pageItem.pageNumber}">${pageItem.pageNumber}</a></li>`;
} else if (pageItem.isCurrentPage()) {
html += `<li>${pageItem.pageNumber}</li>`;
} else if (pageItem.isIgnore()) {
html += `<li>...</li>`;
} else if (pageItem.isNext()) {
html += `<li><a href="/page/${pageItem.pageNumber}">»</a></li>`;
} else {
// `PageItem.ReservedPrev` or `PageItem.ReservedNext` variant is used only when the `hasPrev` option or the `hasNext` option is set to `YesNoDepends.Yes`.
}
}