Created
January 21, 2020 21:42
-
-
Save maisonm/677d36b6585931d42abd40420cec7fc3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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