@@ -17,17 +17,46 @@ const wrapperFactory = baseElement =>
1717 this . handleChangePage = this . handleChangePage . bind ( this ) ;
1818 this . handleChangeSizePerPage = this . handleChangeSizePerPage . bind ( this ) ;
1919
20+ let currPage ;
21+ let currSizePerPage ;
2022 const options = props . pagination . options || { } ;
21- const currPage = options . pageStartIndex || Const . PAGE_START_INDEX ;
2223 const sizePerPageList = options . sizePerPageList || Const . SIZE_PER_PAGE_LIST ;
23- const currSizePerPage = typeof sizePerPageList [ 0 ] === 'object' ? sizePerPageList [ 0 ] . value : sizePerPageList [ 0 ] ;
24+
25+ // initialize current page
26+ if ( typeof options . page !== 'undefined' ) {
27+ currPage = options . page ;
28+ } else if ( typeof options . pageStartIndex !== 'undefined' ) {
29+ currPage = options . pageStartIndex ;
30+ } else {
31+ currPage = Const . PAGE_START_INDEX ;
32+ }
33+
34+ // initialize current sizePerPage
35+ if ( typeof options . sizePerPage !== 'undefined' ) {
36+ currSizePerPage = options . sizePerPage ;
37+ } else if ( typeof sizePerPageList [ 0 ] === 'object' ) {
38+ currSizePerPage = sizePerPageList [ 0 ] . value ;
39+ } else {
40+ currSizePerPage = sizePerPageList [ 0 ] ;
41+ }
42+
2443 this . state = { currPage, currSizePerPage } ;
2544 }
2645
46+ isRemote ( ) {
47+ const { remote } = this . props ;
48+ return remote === true || ( typeof remote === 'object' && remote . pagination ) ;
49+ }
50+
2751 handleChangePage ( currPage ) {
28- const { pagination : { options } } = this . props ;
52+ const { currSizePerPage } = this . state ;
53+ const { pagination : { options } , onRemotePageChange } = this . props ;
2954 if ( options . onPageChange ) {
30- options . onPageChange ( currPage , this . state . currSizePerPage ) ;
55+ options . onPageChange ( currPage , currSizePerPage ) ;
56+ }
57+ if ( this . isRemote ( ) ) {
58+ onRemotePageChange ( currPage , currSizePerPage ) ;
59+ return ;
3160 }
3261 this . setState ( ( ) => {
3362 return {
@@ -37,10 +66,14 @@ const wrapperFactory = baseElement =>
3766 }
3867
3968 handleChangeSizePerPage ( currSizePerPage , currPage ) {
40- const { pagination : { options } } = this . props ;
69+ const { pagination : { options } , onRemotePageChange } = this . props ;
4170 if ( options . onSizePerPageChange ) {
4271 options . onSizePerPageChange ( currSizePerPage , currPage ) ;
4372 }
73+ if ( this . isRemote ( ) ) {
74+ onRemotePageChange ( currPage , currSizePerPage ) ;
75+ return ;
76+ }
4477 this . setState ( ( ) => {
4578 return {
4679 currPage,
@@ -60,25 +93,31 @@ const wrapperFactory = baseElement =>
6093 Const . HIDE_SIZE_PER_PAGE : options . hideSizePerPage ;
6194 const hidePageListOnlyOnePage = typeof options . hidePageListOnlyOnePage === 'undefined' ?
6295 Const . HIDE_PAGE_LIST_ONLY_ONE_PAGE : options . hidePageListOnlyOnePage ;
96+ const pageStartIndex = typeof options . pageStartIndex === 'undefined' ?
97+ Const . PAGE_START_INDEX : options . pageStartIndex ;
98+
99+ const data = this . isRemote ( ) ?
100+ this . props . data :
101+ store . getByCurrPage ( currPage , currSizePerPage , pageStartIndex ) ;
63102
64103 const base = baseElement ( {
65104 ...this . props ,
66105 key : 'table' ,
67- data : store . getByCurrPage ( currPage , currSizePerPage )
106+ data
68107 } ) ;
69108
70109 return [
71110 base ,
72111 < Pagination
73112 key = "pagination"
74- dataSize = { this . props . store . getDataSize ( ) }
113+ dataSize = { options . totalSize || store . getDataSize ( ) }
75114 currPage = { currPage }
76115 currSizePerPage = { currSizePerPage }
77116 onPageChange = { this . handleChangePage }
78117 onSizePerPageChange = { this . handleChangeSizePerPage }
79118 sizePerPageList = { options . sizePerPageList || Const . SIZE_PER_PAGE_LIST }
80119 paginationSize = { options . paginationSize || Const . PAGINATION_SIZE }
81- pageStartIndex = { options . pageStartIndex || Const . PAGE_START_INDEX }
120+ pageStartIndex = { pageStartIndex }
82121 withFirstAndLast = { withFirstAndLast }
83122 alwaysShowAllBtns = { alwaysShowAllBtns }
84123 hideSizePerPage = { hideSizePerPage }
0 commit comments