-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[docs] Add section for controlled selection and server-side pagination #2602
[docs] Add section for controlled selection and server-side pagination #2602
Conversation
{{"demo": "pages/components/data-grid/selection/ControlledSelectionGrid.js", "bg": "inline"}} | ||
|
||
### Controlled selection and server-side pagination | ||
|
||
Using controlled selection when `paginationMode="server"` can result in the `DataGrid` clearing the provided `selectionModel` on page change. Depending on your implementation of the server-side pagination, when the page changes and there are no rows in the grid with ids equal to the `GridRowId`s provided to the `selectionModel` the grid will clear the `selectionModel`. To prevent this either save the `selectionModel` and restore it later or append the newly loaded grid rows to the existing rows. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and restore it later
Some people will probably struggle to implement it.
Maybe we could also add an example for this part, or just take for granted that appending the rows is the way we want to encourage.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm opened to suggestions here. It's unclear what the desired behaviour should be. For me, the way it is looks correct but so does the initial implementation in the ticket (not appending the rows). Because the selection is controlled the only solution I can see is either to leave it as it is or prevent the grid from cleaning up the selectionModel
if the rows are missing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess we can start by explaining only the row-concatenation as you did
And if we have feedback asking for the selection-restoration approach, add another dedicated example later on.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably also take this #2602 (comment) into consideration. If we want to fix that as well we will need to change the way the selectionModel
behaves as the Select All feature is not really server-side friendly at the moment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed
Doesn't this break the functionality of the "select all" checkbox in the grid header? Using this demo, try the following:
|
This is how the Select All feature works when the pagination is client-side. |
The client-side mode will select every row. It will not do this for server-side; it'll only select the rows that have been downloaded. It feels unintuitive and somewhat misleading for the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could add a note in https://mui.com/components/data-grid/pagination/#server-side-pagination linking to the new section.
Co-authored-by: Matheus Wichman <[email protected]>
Co-authored-by: Matheus Wichman <[email protected]>
Co-authored-by: Matheus Wichman <[email protected]>
@m4theushw @flaviendelangle if we agree to investigate the select all issue in a separate PR should we proceed with merging this one? |
@DanailH the select all issue is not caused by this PR so no problem for fixing it on a following one. I take a last look at the texts of this PR and I approve 👍 |
The Select All issue is because we're appending rows. If the user change the page a bunch of times and later he select all rows, the number of selected rows will be the total count. The workaround is not good to be a "official" solution. We could explore the first solution for the docs. It requires a CX9ndMSAEX.mp4About the definitive solution to be done in another PR. I think we should allow to have non-existing IDs in the |
I devised a crude work-around that attempts to fix the issue of "select all" selecting more than the current page by using It doesn't automatically select rows on any new pages that user hasn't already browsed, so I'd have to keep track of an "all selected" state independent of the data grid and trigger |
For now, we can go with the option @m4theushw proposed (with saving the |
@@ -43,6 +43,8 @@ Finally, you need to handle the `onPageChange` callback to load the rows for the | |||
|
|||
{{"demo": "pages/components/data-grid/pagination/ServerPaginationGrid.js", "bg": "inline"}} | |||
|
|||
**Note**: For more information regarding server-side pagination in combination with controlled selection check [here](/components/data-grid/selection/#usage-with-server-side-pagination) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two feedback on this one. A sentence should have a closing dot. "here" is considered to be avoided as link description: https://www.w3.org/QA/Tips/noClickHere. Maybe?
**Note**: For more information regarding server-side pagination in combination with controlled selection check [here](/components/data-grid/selection/#usage-with-server-side-pagination) | |
**Note**: For more information regarding server-side pagination in combination with controlled selection check [the dedicated section](/components/data-grid/selection/#usage-with-server-side-pagination). |
Fixes #1782
Updated the docs with the explanation of why the
selectionModel
might be cleared when new rows are loaded on page change whenpaginationMode="server"
.