Skip to content
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

[DataGrid] Fix isRowSelectable when paginationMode='server' #3647

Merged

Conversation

flaviendelangle
Copy link
Member

@flaviendelangle flaviendelangle commented Jan 17, 2022

Fixes #3614

Small performance improvement: we don't call isRowSelectable for every row in GridBody but only on rendered rows.

For the header checkbox, the behavior remain incoherent with paginationMode="server" because we don't know if there are unselected rows on other pages.
I think we can fix that one in a follow up PR by adding a getSelectAllStatus callback for instance, which would return 'all' | 'none' | 'some'.


  • Tests

@flaviendelangle flaviendelangle self-assigned this Jan 17, 2022
@mui-bot
Copy link

mui-bot commented Jan 17, 2022

These are the results for the performance tests:

Test case Unit Min Max Median Mean σ
Filter 100k rows ms 176.8 389.7 300.9 291.82 78.646
Sort 100k rows ms 430.3 809.2 781.8 687.92 144.039
Select 100k rows ms 155.5 266.9 216.9 213.24 36.864
Deselect 100k rows ms 104.5 515.2 173.7 219.1 151.259

Generated by 🚫 dangerJS against f1e2db7

@flaviendelangle flaviendelangle marked this pull request as draft January 17, 2022 08:42
@flaviendelangle flaviendelangle marked this pull request as ready for review January 17, 2022 13:29
@flaviendelangle flaviendelangle changed the title [DataGrid] Fix isRowSelectable when paginationMode='server' [DataGrid] Fix isRowSelectable when paginationMode='server' Jan 17, 2022
if (selectedRowsLookup[id] == null) {
isSelected = false;
} else if (typeof rootProps.isRowSelectable === 'function') {
isSelected = rootProps.isRowSelectable(apiRef.current.getRowParams(id));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if this change is good. In the previous way, the selection lookup was already filtered all at once and memoized. Now isRowSelectable might be called several times for the same row. I'm OK to call it for every currentPage.rows and memoize the result.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My thought behind this is that renderedRows will never be hundreds of rows long whereas currentPage.rows might have 100 000 items.
But I could memoize renderedRows and create a memoized selection lookup based on renderedRows.
That way we don't loop on the potentially very long currentPage.rows and we only re-run when the 1st and/or last rendered rows changes.

@flaviendelangle flaviendelangle added component: data grid This is the name of the generic UI component, not the React module! bug 🐛 Something doesn't work labels Jan 19, 2022
@github-actions
Copy link

This pull request has conflicts, please resolve those before we can evaluate the pull request.

@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Jan 25, 2022
@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label Jan 25, 2022
@flaviendelangle flaviendelangle merged commit 80bf843 into mui:master Jan 25, 2022
@flaviendelangle flaviendelangle deleted the selection-controlled-pagination branch January 25, 2022 15:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something doesn't work component: data grid This is the name of the generic UI component, not the React module!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[DataGrid] isRowSelectable returns an error when using server side selection
3 participants