) {
if (this.props.onChangeItemsPerPage) {
this.props.onChangeItemsPerPage(
parseInt((evt.target as HTMLSelectElement).value, 10)
);
}
}
handleShowMore() {
if (
this.props.itemsPerPageOptions &&
this.props.itemsPerPageOptions.length > 0 &&
this.props.itemsPerPage &&
this.props.onChangeItemsPerPage
) {
const index = this.props.itemsPerPageOptions.indexOf(
this.props.itemsPerPage
);
if (
index > -1 &&
index < this.props.itemsPerPageOptions.length - 1
) {
this.props.onChangeItemsPerPage(
this.props.itemsPerPageOptions[index + 1]
);
} else {
this.props.onChangeItemsPerPage(
this.props.itemsPerPage +
this.props.itemsPerPageOptions[
this.props.itemsPerPageOptions.length - 1
]
);
}
}
}
resetItemsPerPage() {
this.props.onChangeItemsPerPage &&
this.props.itemsPerPageOptions &&
this.props.itemsPerPageOptions.length > 0 &&
this.props.onChangeItemsPerPage(this.props.itemsPerPageOptions[0]);
}
private getSectionBetweenPaginationButtons() {
if (this.props.showMoreButton) {
return (
);
} else {
return (
{this.props.textBetweenButtons}
);
}
}
private get shouldHidePaginationControls() {
return (
this.props.hidePaginationIfOnePage &&
this.props.itemsPerPageOptions &&
typeof this.props.totalItems !== 'undefined' &&
this.props.itemsPerPageOptions[0] >= this.props.totalItems
);
}
render() {
const pageSizeOptionElts = (this.props.itemsPerPageOptions || []).map(
(opt: number) => (
)
);
if (this.props.showAllOption) {
pageSizeOptionElts.push(
);
}
let buttons: any = [
,
,
this.getSectionBetweenPaginationButtons(),
,
,
,
];
if (this.props.groupButtons) {
buttons = (
{buttons}
);
} else {
buttons = {buttons}
;
}
if (this.shouldHidePaginationControls) {
buttons = null;
}
return (
{this.props.textBeforeButtons}
{buttons}
}
>
{pageSizeOptionElts}
);
}
}
export default PaginationControls;