@heppokofrontend/pager
v0.1.1
Published
Wrapping iterable objects with the pager function.
Downloads
1
Maintainers
Readme
@heppokofrontend/pager
Wrapping iterable objects with the pager function.
Usage
Installation:
npm install --save @heppokofrontend/pager
Instance
Properties
|property name|type|readonly|description|
|---|---|---|---|
|values
|T[]
|true
|Iterable objects to be managed by the pager.|
|views
|number
||Number of items to be displayed per page.|
|set index()
|number
||Page number to move to.|
|get index()
|number
||The current page number.|
|get lastIndex()
|number
|true
|Last page number.|
|get page()
|T[]
|true
|Items on the current page.It is recommended to cache the got values.|
Methods
|method name|type|description|
|---|---|---|
|current()
|(index: number) => T[]
|Switch the current page to any page.|
|next()
|() => T[]
|Switch the current page to the next.|
|prev()
|() => T[]
|Switch the current page to the previous.|
Syntax
new Pager(values[, views])
values
Any iterable object.
views
If specified, number of items to be displayed per page.
The default value is 5
.
Example:
import { Pager } from '@heppokofrontend/pager';
// const { Pager } = require('@heppokofrontend/pager');
const pager = new Pager([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
pager.current(1); // => [6, 7, 8, 9, 10]
pager.current(-1); // => [1, 2, 3, 4, 5]
pager.current(pager.lastIndex); // => [6, 7, 8, 9, 10]
pager.current(100); // => [6, 7, 8, 9, 10]
pager.lastIndex // => 2
pager.views = 2; // Change the number of views per page.
pager.lastIndex // => 5
pager.current(1); // => [3, 4]
pager.current(200); // => [9, 10]
pager.page // => [9, 10]
pager.index = 3; // Change the current page number
pager.page // => [7, 8]
pager.current(7); // => [7, 8]
Contributing
- Fork it!
- Create your feature branch:
git checkout -b my-new-feature
- Commit your changes:
git commit -am 'Add some feature'
- Push to the branch:
git push origin my-new-feature
- Submit a pull request :D
License
MIT