Skip to content

Instantly share code, notes, and snippets.

@maisonm
Created January 21, 2020 21:42
Show Gist options
  • Save maisonm/677d36b6585931d42abd40420cec7fc3 to your computer and use it in GitHub Desktop.
Save maisonm/677d36b6585931d42abd40420cec7fc3 to your computer and use it in GitHub Desktop.
determineNumberOfPages = () => {
const { data, itemsPerPage } = this.props;
let paginatedDataObject = {};
let index = 0;
let dataLength = data.length;
let chunkArray = [];
for (index = 0; index < dataLength; index += itemsPerPage) {
let newChunk = data.slice(index, index + itemsPerPage);
chunkArray.push(newChunk);
}
chunkArray.forEach((chunk, i) => {
paginatedDataObject[i + 1] = chunk;
});
this.setState({
totalPages: chunkArray.length,
dataStartingIndex: itemsPerPage,
pageData: paginatedDataObject,
clickedOnNumber: 1
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment