admin管理员组文章数量:1385002
By using <DataGrid autoPageSize/>
, as described in the docs, you can get a Material UI table that automatically sets the page size (ie the number of rows per page) based on the browser height. However, if you are progressively loading data from the server, you need to know what that page size is, in order to know how much data to load per page, and which row the table is up to. As far as I can tell, the DataGrid
only gives you access to the page number (through various events) which doesn't let you determine the page size.
The ponent does give you access to a pageSizeChange
event, but this doesn't actually fire when the ponent automatically sets its page size using autoPageSize
, so it doesn't help here.
By using <DataGrid autoPageSize/>
, as described in the docs, you can get a Material UI table that automatically sets the page size (ie the number of rows per page) based on the browser height. However, if you are progressively loading data from the server, you need to know what that page size is, in order to know how much data to load per page, and which row the table is up to. As far as I can tell, the DataGrid
only gives you access to the page number (through various events) which doesn't let you determine the page size.
The ponent does give you access to a pageSizeChange
event, but this doesn't actually fire when the ponent automatically sets its page size using autoPageSize
, so it doesn't help here.
2 Answers
Reset to default 3I also ran into the same issue of trying to use DataGrid with server-side pagination. After some digging around, I found that I'm able to see that onPageSizeChange
is triggered when the ponent first loads. See this codesandbox.
If you look at the console after refreshing the codesandbox browser, it prints 0, then 5. You could save this into state and then use it in your onPageChange
calls.
2023 update - MUI X 6.18.4
UPDATE: the accepted answer is a bit older and the onPageSizeChange
is indeed not available anymore I found out that you can get the calculated page size through the onPaginationModelChange
.
you also get this information through the onStateChange
but you will have to dig a bit to find it. (It's located in pagination.paginationModel.pageSize
).
本文标签: javascriptAccess the page size in a Material UI ltDataGrid autoPageSizegtStack Overflow
版权声明:本文标题:javascript - Access the page size in a Material UI `<DataGrid autoPageSize>` - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744454543a2606924.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论