aboutsummaryrefslogtreecommitdiff
path: root/src/shared/paginator.component.js
diff options
context:
space:
mode:
authorIndrajith K L2019-12-12 21:02:20 +0530
committerIndrajith K L2019-12-12 21:02:20 +0530
commit5e3d9da21510e1622bcf900a949c8506e4251bce (patch)
treea86fe926c11f47064d2f9fa8a7bfae6496e04d26 /src/shared/paginator.component.js
parent7593008ad2d8f65321a7a5992d1cda79b1083123 (diff)
downloadreact-redux-saga-starter-5e3d9da21510e1622bcf900a949c8506e4251bce.tar.gz
react-redux-saga-starter-5e3d9da21510e1622bcf900a949c8506e4251bce.tar.bz2
react-redux-saga-starter-5e3d9da21510e1622bcf900a949c8506e4251bce.zip
:sparkles: Adds Paginator Component
Diffstat (limited to 'src/shared/paginator.component.js')
-rw-r--r--src/shared/paginator.component.js50
1 files changed, 50 insertions, 0 deletions
diff --git a/src/shared/paginator.component.js b/src/shared/paginator.component.js
new file mode 100644
index 0000000..9512d4e
--- /dev/null
+++ b/src/shared/paginator.component.js
@@ -0,0 +1,50 @@
+import React from 'react';
+import _ from 'lodash';
+
+const Paginator = (props) => {
+
+ let {totalRecords=0, currentPage=1, pageSize=15} = props;
+ let pages = [1];
+ let previousItemStyle = totalRecords<pageSize ? 'page-item disabled' : 'page-item';
+ let nextItemStyle = totalRecords<pageSize ? 'page-item disabled' : 'page-item';
+
+ if(totalRecords>pageSize){
+ pages = _.times(parseInt(totalRecords/pageSize,10));
+ }
+
+ const onPrevious = ()=>{
+ props.previousPage();
+ }
+
+ const onNext = ()=>{
+ props.nextPage();
+ }
+
+ const onPageClick = (pageNum)=>{
+ props.goToNextPage(pageNum)
+ }
+
+
+ return (
+ <nav>
+ <ul className="pagination">
+ <li className={previousItemStyle}>
+ <a className="page-link" href="javascript:void(0)" onClick={onPrevious}>Previous</a>
+ </li>
+
+ {pages.map(_page=>{
+ return(
+ <li key={_page} className={_page==currentPage ? "page-item active" : "page-item"}>
+ <a className="page-link" href="javascript:void(0)" onClick={onPageClick.bind(this, _page)}>{_page}</a>
+ </li>
+ )
+ })}
+ <li className={nextItemStyle}>
+ <a className="page-link" href="#" onClick={onNext}>Next</a>
+ </li>
+ </ul>
+ </nav>
+ )
+}
+
+export default Paginator;