From 21cfa7b750823ce5f5c9b2ee2885e1bfccf04f9f Mon Sep 17 00:00:00 2001 From: mertsincan Date: Tue, 21 May 2019 11:54:48 +0300 Subject: [PATCH] Fixed #896 - alwaysShowPaginator prop not used --- src/components/datatable/DataTable.js | 2 +- src/components/dataview/DataView.js | 2 +- src/components/paginator/Paginator.js | 109 ++++++++++++++------------ src/components/treetable/TreeTable.js | 2 +- 4 files changed, 61 insertions(+), 54 deletions(-) diff --git a/src/components/datatable/DataTable.js b/src/components/datatable/DataTable.js index 0b4d6f40d0..d1e49b32de 100644 --- a/src/components/datatable/DataTable.js +++ b/src/components/datatable/DataTable.js @@ -435,7 +435,7 @@ export class DataTable extends Component { return ( + leftContent={this.props.paginatorLeft} rightContent={this.props.paginatorRight} alwaysShow={this.props.alwaysShowPaginator} /> ); } diff --git a/src/components/dataview/DataView.js b/src/components/dataview/DataView.js index 1ebe962d91..eecc7242b6 100644 --- a/src/components/dataview/DataView.js +++ b/src/components/dataview/DataView.js @@ -161,7 +161,7 @@ export class DataView extends Component { return ( + leftContent={this.props.paginatorLeft} rightContent={this.props.paginatorRight} alwaysShow={this.props.alwaysShowPaginator} /> ); } diff --git a/src/components/paginator/Paginator.js b/src/components/paginator/Paginator.js index c27e822798..8efb8a40ef 100644 --- a/src/components/paginator/Paginator.js +++ b/src/components/paginator/Paginator.js @@ -23,7 +23,8 @@ export class Paginator extends Component { onPageChange: null, leftContent: null, rightContent: null, - currentPageReportTemplate: '({currentPage} of {totalPages})' + currentPageReportTemplate: '({currentPage} of {totalPages})', + alwaysShow: true } static propTypes = { @@ -38,7 +39,8 @@ export class Paginator extends Component { onPageChange: PropTypes.func, leftContent: PropTypes.any, rightContent: PropTypes.any, - currentPageReportTemplate: PropTypes.any + currentPageReportTemplate: PropTypes.any, + alwaysShow: PropTypes.bool } constructor(props) { @@ -142,58 +144,63 @@ export class Paginator extends Component { } render() { - let className = classNames('p-paginator p-component p-unselectable-text', this.props.className); - - let paginatorElements = this.props.template.split(' ').map((value) => { - let key = value.trim(); - let element; + if (!this.props.alwaysShow && this.getPageCount() === 1) { + return null; + } + else { + let className = classNames('p-paginator p-component p-unselectable-text', this.props.className); - switch(key) { - case 'FirstPageLink': - element = ; - break; - - case 'PrevPageLink': - element = ; - break; - - case 'NextPageLink': - element = ; - break; - - case 'LastPageLink': - element = ; - break; - - case 'PageLinks': - element = ; - break; + let paginatorElements = this.props.template.split(' ').map((value) => { + let key = value.trim(); + let element; - case 'RowsPerPageDropdown': - element = ; - break; + switch(key) { + case 'FirstPageLink': + element = ; + break; + + case 'PrevPageLink': + element = ; + break; + + case 'NextPageLink': + element = ; + break; + + case 'LastPageLink': + element = ; + break; + + case 'PageLinks': + element = ; + break; + + case 'RowsPerPageDropdown': + element = ; + break; + + case 'CurrentPageReport': + element = ; + break; + + default: + element = null; + break; + } - case 'CurrentPageReport': - element = ; - break; - - default: - element = null; - break; - } + return element; + }); + + let leftContent = this.props.leftContent &&
{this.props.leftContent}
; + let rightContent = this.props.rightContent &&
{this.props.rightContent}
- return element; - }); - - let leftContent = this.props.leftContent &&
{this.props.leftContent}
; - let rightContent = this.props.rightContent &&
{this.props.rightContent}
- - return ( -
- {leftContent} - {paginatorElements} - {rightContent} -
- ); + return ( +
+ {leftContent} + {paginatorElements} + {rightContent} +
+ ); + } } } \ No newline at end of file diff --git a/src/components/treetable/TreeTable.js b/src/components/treetable/TreeTable.js index 889e001ca7..8166c7e1f1 100644 --- a/src/components/treetable/TreeTable.js +++ b/src/components/treetable/TreeTable.js @@ -910,7 +910,7 @@ export class TreeTable extends Component { + leftContent={this.props.paginatorLeft} rightContent={this.props.paginatorRight} alwaysShow={this.props.alwaysShowPaginator} /> ) }