Skip to content

Commit

Permalink
Fixed #636 - Add currentPageReportTemplate property to Paginator
Browse files Browse the repository at this point in the history
  • Loading branch information
Merve7 committed Nov 28, 2018
1 parent a76e5f8 commit f4e96e5
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
9 changes: 4 additions & 5 deletions src/components/paginator/CurrentPageReport.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,18 @@ export class CurrentPageReport extends Component {
static defaultProps = {
pageCount: null,
page: null,
template: '({currentPage} of {totalPages})'
currentPageReportTemplate: null
}

static propsTypes = {
pageCount: PropTypes.number,
page: PropTypes.number,
template: PropTypes.string
currentPageReportTemplate: PropTypes.any
}

render() {
let text = this.props.template
.replace("{currentPage}", this.props.page + 1)
.replace("{totalPages}", this.props.pageCount);
let text = this.props.currentPageReportTemplate ? this.props.currentPageReportTemplate :
'('+(this.props.page + 1)+' of '+(this.props.pageCount)+')';

return <span className="p-paginator-current">{text}</span>
}
Expand Down
8 changes: 5 additions & 3 deletions src/components/paginator/Paginator.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ export class Paginator extends Component {
template: 'FirstPageLink PrevPageLink PageLinks NextPageLink LastPageLink RowsPerPageDropdown',
onPageChange: null,
leftContent: null,
rightContent: null
rightContent: null,
currentPageReportTemplate: null
}

static propsTypes = {
Expand All @@ -36,7 +37,8 @@ export class Paginator extends Component {
template: PropTypes.string,
onPageChange: PropTypes.func,
leftContent: PropTypes.any,
rightContent: PropTypes.any
rightContent: PropTypes.any,
currentPageReportTemplate: PropTypes.any
}

constructor(props) {
Expand Down Expand Up @@ -172,7 +174,7 @@ export class Paginator extends Component {
break;

case 'CurrentPageReport':
element = <CurrentPageReport key={key} page={this.getPage()} pageCount={this.getPageCount()} />;
element = <CurrentPageReport currentPageReportTemplate={this.props.currentPageReportTemplate} key={key} page={this.getPage()} pageCount={this.getPageCount()} />;
break;

default:
Expand Down
6 changes: 6 additions & 0 deletions src/showcase/paginator/PaginatorDemo.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,12 @@ import {Paginator} from 'primereact/paginator';
<td>null</td>
<td>Content to inject into the right side of the paginator.</td>
</tr>
<tr>
<td>currentPageReportTemplate</td>
<td>any</td>
<td>null</td>
<td>Content to CurrentPageReport template of the paginator.</td>
</tr>
</tbody>
</table>
</div>
Expand Down

0 comments on commit f4e96e5

Please sign in to comment.