I have a react data table where I recently added pagination for when you have many entries. I wanted the option to show all entries in the table by selecting "all" in the rowsPerPageOptions dropdown menu. So far I managed to get the count of all entries to show up in the menu.
What I need now is to label the entries.length
object with the string "all" and get that to show up in the menu. Is that possible?
When I try something like all.push({label: this.state.entries.length});
I get the error:
Objects are not valid as a React child (found: object with keys {label}). If you meant to render a collection of children, use an array instead.
That made me think that I can not use arrays with keys for the menu, so I have to show that value in a different way.
Code:
Edit: Moved the all variable into the render function after morteza ataiy commented and pointed out an error.
render() {
return (
let all = [5,10,25,50,(this.state.entries.length)];
<div>
<Table>
</Table>
</div>
<TablePagination
component="div"
count={this.state.entries.length}
rowsPerPage={this.state.rowsPerPage}
page={this.state.page}
backIconButtonProps={{
'aria-label': 'Previous Page',
}}
nextIconButtonProps={{
'aria-label': 'Next Page',
}}
onChangePage={this.handleChangePage}
onChangeRowsPerPage={this.handleChangeRowsPerPage}
labelRowsPerPage="Reihen pro Seite:"
rowsPerPageOptions={all}
);
}
Image: The last entry is what I want to change
Please keep in mind that I am new to React and JavaScript, thanks in advance!