-
-
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
[data grid] All grouped rows collapses when rows updating (by state, not by updateRows) #13064
Comments
Hey @iOrcohen thanks for opening this issue. The behavior you are describing is actually to be expected, when providing a new This can be avoided when using the @cherniavskii is there any plan of including the row-expansion state in the grid state? |
@michelengelen Thanks for your comment! If the plan is to the add the row-expansion to the grid state, let me know and I might contribute it myself :) Thanks again. |
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
Related discussion: #7771 We might reconsider the default behavior for the next major since the current behavior is clearly confusing to many users. |
Hi all, I've developed a band-aid solution to this, leveraging (a) the internal state's storage of whether rows belonging to a group are visible pre-update and (b) the fact that group rows can be dynamically identified by their prefix. Sharing in case it helps anybody else, as this was driving me nuts! Initialise a dynamic state for expanded row groups const [expandedGroups, setExpandedGroups] = useState<string[]>([]); ... The main function const HandleNodeClick_withSavedExpandState = useCallback(
debounce((node) => {
// Get current apiRef state
const CurrentGridState = apiRef.current.state;
// Dynamically identify the group headings that are currently visible by using the visibleRowsLookup object, and the fact that group headings start with "auto-generated-row-type/"
const visibleGroups = Object.keys(CurrentGridState.visibleRowsLookup).filter(row => row.startsWith('auto-generated-row-type/'));
// Store the identified group headings for reference
const visibleGroupsWithoutPrefix = visibleGroups.map(row => row.replace('auto-generated-row-type/', ''));
// To check if each group is currently expanded, check if the first row of each group is visible
const firstRowOfEachGroup = visibleGroups.map(groupId =>
apiRef.current.getRowGroupChildren({groupId})[0]
);
const firstRowVisibility = firstRowOfEachGroup.map(row => CurrentGridState.visibleRowsLookup[row]);
// Build an array of the visible groups (without prefix), based on those for which which the first row is visible
const visibleExpandedGroups = visibleGroupsWithoutPrefix.filter((_, index) => firstRowVisibility[index]);
console.log('Visible Expanded Groups: ', visibleExpandedGroups);
// Pass this array of expanded groups to the state for the next render
setExpandedGroups(visibleExpandedGroups);
// Call the original trigger for a state update
originalHandleNodeClick(node);
}, 300),
[]
); ... Define the 'isGroupExpandedByDefault' parameter dynamically const isGroupExpandedByDefault = useCallback((node: GridGroupNode) =>
node.groupingField === '[YOUR_GROUP_FIELD_NAME_HERE]' && expandedGroups.includes(String(node.groupingKey)), [expandedGroups]); ... Include the parameter in your DataGrid output <DataGridPremium
isGroupExpandedByDefault={isGroupExpandedByDefault} /> |
I am also experiencing this bug and it significantly impacts my work. It would be greatly appreciated if a fix could be provided soon. Thank you for your attention to this matter. |
Thanks Sam for the workaround! For what its worth, I would also greatly appreciate official support to keep the rows expanded on interaction. |
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
@cherniavskii Yeah, I think that it would make sense to reopen #7771 too. As far as I remember, the As a developer, I would expect those:
Now, I guess tree data and row grouping are powered by the same state, so #7771 and #13064 are the same issues. |
@oliviertassinari is this a new bug? As far as I can tell, this was not happening until we upgraded to data grid premium v7. I think we were on data grid pro v5 before... pretty sure everything was working just fine up until that upgrade, as complaints from our users about this issue have only started very recently. (Although, I can't say for sure that upgrading was the reason since other changes have gone in as well since then--however no changes that I can see which would affect whether or not rows are memoized... we have never memoized rows, only columns.) (Note: we are not using row grouping, but tree data. Is it possible that previously, in v5, the expansion state was correctly linked to either the row IDs or the tree data path--which I would expect--but in v7, the expansion state was erroneously linked to the row's object identity instead? Like I said, we have never memoized rows and the expansion state was definitely working correctly prior to our upgrade to v7.) |
do you know if the next release is going to incudes a fix for that issue? |
Steps to reproduce
Link to live example: code sandbox
Steps:
Current behavior
All groups collapses after the rows state changed.
Expected behavior
Groups expansion won't be effected by the rows change.
Context
We update the table rows with fresh data every one minute in our application (It's include coins prices data which require often refresh).
After every refresh all the groups collapses automatically, which make unpleasant user experience.
Your environment
npx @mui/envinfo
Search keywords: expansion, grouping
Order ID: 66471 + 90144
The text was updated successfully, but these errors were encountered: