admin管理员组文章数量:1295651
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 mented and pointed out an error.
render() {
return (
let all = [5,10,25,50,(this.state.entries.length)];
<div>
<Table>
</Table>
</div>
<TablePagination
ponent="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!
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 mented and pointed out an error.
render() {
return (
let all = [5,10,25,50,(this.state.entries.length)];
<div>
<Table>
</Table>
</div>
<TablePagination
ponent="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!
Share Improve this question edited Aug 15, 2018 at 11:42 Jay-Way asked Aug 15, 2018 at 11:20 Jay-WayJay-Way 3381 gold badge3 silver badges15 bronze badges 2-
Why you add
let all = [...
afterreturn
? move it betweenrender
andreturn
– morteza ataiy Commented Aug 11, 2019 at 20:52 - Please, check mi answer in React material table automatic page size – Jorge Santos Neill Commented Oct 2, 2019 at 0:47
2 Answers
Reset to default 3You can use label . plz refer the code
<TablePagination rowsPerPageOptions={[10, 50, { value: -1, label: 'All' }]} />
You can pass -1 to the backend and write query with respect to this.
just use it in render method:
render() {
let all = [5,10,25,50,(this.state.entries.length)];
return (
<div>
<Table>
</Table>
</div>
<TablePagination
ponent="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}
}
本文标签: javascriptReact with Material UI Table Pagination show all entriesStack Overflow
版权声明:本文标题:javascript - React with Material UI Table Pagination show all entries - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741618977a2388696.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论