diff --git a/samples/react-accordion/src/webparts/reactAccordion/components/IReactAccordionState.ts b/samples/react-accordion/src/webparts/reactAccordion/components/IReactAccordionState.ts index 9ad6c65af..be770bfa3 100644 --- a/samples/react-accordion/src/webparts/reactAccordion/components/IReactAccordionState.ts +++ b/samples/react-accordion/src/webparts/reactAccordion/components/IReactAccordionState.ts @@ -2,8 +2,9 @@ import IAccordionListItem from '../models/IAccordionListItem'; export interface IReactAccordionState { status: string; + pagedItems: IAccordionListItem[]; items: IAccordionListItem[]; listItems: IAccordionListItem[]; isLoading: boolean; loaderMessage: string; -} \ No newline at end of file +} diff --git a/samples/react-accordion/src/webparts/reactAccordion/components/ReactAccordion.tsx b/samples/react-accordion/src/webparts/reactAccordion/components/ReactAccordion.tsx index 95671e6bb..87801a6a0 100644 --- a/samples/react-accordion/src/webparts/reactAccordion/components/ReactAccordion.tsx +++ b/samples/react-accordion/src/webparts/reactAccordion/components/ReactAccordion.tsx @@ -26,6 +26,7 @@ export default class ReactAccordion extends React.Component { this.setState({ status: 'Loading all items failed with error: ' + error, - items: [], + pagedItems: [], isLoading: false, loaderMessage: "" }); @@ -102,18 +110,19 @@ export default class ReactAccordion extends React.Component { let displayLoader; let faqTitle; - let { listItems } = this.state; + let { items } = this.state; let pageCountDivisor: number = this.props.maxItemsPerPage; let pageCount: number; let pageButtons = []; let _pagedButtonClick = (pageNumber: number, listData: any) => { let startIndex: number = (pageNumber - 1) * pageCountDivisor; + let endIndex = startIndex + pageCountDivisor; let listItemsCollection = [...listData]; - this.setState({ items: listItemsCollection.splice(startIndex, pageCountDivisor) }); + this.setState({ pagedItems: listItemsCollection.slice(startIndex, endIndex) }); }; - const items: JSX.Element[] = this.state.items.map((item: IAccordionListItem, i: number): JSX.Element => { + const pagedItems: JSX.Element[] = this.state.pagedItems.map((item: IAccordionListItem, i: number): JSX.Element => { return ( @@ -139,11 +148,11 @@ export default class ReactAccordion extends React.Component 0) { - pageCount = Math.ceil(this.state.listItems.length / pageCountDivisor); + if (items.length > 0) { + pageCount = Math.ceil(items.length / pageCountDivisor); } for (let i = 0; i < pageCount; i++) { - pageButtons.push( { _pagedButtonClick(i + 1, listItems); }}> {i + 1} ); + pageButtons.push( { _pagedButtonClick(i + 1, items); }}> {i + 1} ); } return (
@@ -164,7 +173,7 @@ export default class ReactAccordion extends React.Component {this.state.status} - {items} + {pagedItems}