-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpaginate.js
46 lines (36 loc) · 1.1 KB
/
paginate.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import _ from 'lodash';
export function paginate(items, pageNumber, pageSize) {
const startIndex = (pageNumber -1) * pageSize;
return _(items)
.slice(startIndex)
.take(pageSize)
.value();
};
// Main State Requirements ------
// state = {
// currentPage: 1,
// pageSize: 4
// };
// Main component functions --------
// handlePageChange = page => {
// console.log("page#",page)
// this.setState({currentPage: page});
// };
// handleNext = (page, pagesCount) => {
// if(page < pagesCount) {
// this.setState({currentPage: page += 1});
// }
// this.setState({currentPage: page});
// };
// handlePrev = (page) => {
// if(page > 1) {
// this.setState({currentPage: page -= 1});
// }
// this.setState({currentPage: page});
// };
// Main component mark-up -----------------------
// const {List, pageSize, currentPage} = this.state;
// const paginatedItems = paginate(List, currentPage, pageSize);
// <Pagination itemsCount={count} pageSize={pageSize}
// currentPage={currentPage} onPageChange={this.handlePageChange}
// onPagePrev={this.handlePrev} onPageNext={this.handleNext}/>