Javascript Pagination Class

Provides calculations for paging elements.

Class properties

Example of usage

Initialization

var pagination, pagingInfo;

pagination = new Pagination({
	total: 100,
	perPage: 5,
	page: 15
});

pagingInfo = pagination.toJSON();

Outputs:

pagingInfo -> {
	page: 15,
	perPage: 5,
	total: 100,
	items: [70, 75],

	prev: 14,
	next: 16,

	first: false,
	last: false,

	pages: [11, 20],
	totalPages: 20,
	pagesPerPage: 10
};

Updating existing instance

// set all changed properties
pagination.set({
	page: 3,
	perPage: 16
});
// then
pagingInfo = pagination.toJSON();

Outputs:

pagingInfo -> {
	page: 3,
	perPage: 16,
	total: 100,
	items: [32, 48],

	prev: 2,
	next: 4,

	first: false,
	last: false,

	pages: [1, 7],
	totalPages: 7,
	pagesPerPage: 10
};