Sorting Master List Does NOT Keep Detail Below Master Row #3394
-
I was able to implement a master/detail list using the same approach as provided in the demo site/code. My master list, unlike the demo, has sortable columns. Works fine until I sort and then the detail view gets mucked up and is at the bottom or top depending on the sort direction. Am wondering if anyone has implemented a similar feature as I have or if you have some suggestion as to how to fix so the detail stays "pinned" to its parent? Thank you for any help. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
I found what seems to be a solution but not rock solid yet. I noticed I'd only need this in descending so in my sortedRows useMemo/cached function, after the sort is done, I check if the direction is descending and basically swap out the detail row position with its master. So something like this seems to do the trick:
My other issue, which is why this is not solid yet, is that the master row shifts its position when I expand the detail view when the master list is sorted in descending order why whatever column. Not sure yet what's going on there but the position reflects what's in the dataset and does NOT happen when ascending. Any helpful input on that would be appreciated. I hope the above helps someone else. |
Beta Was this translation helpful? Give feedback.
-
I think I have this finally resolved. I did some more digging into the data grid guts in the demo and source code and did find a good approach with sorting use a getComparator function, I followed that pattern (found it in
I hope this helps someone else who may be running into the same issue. One thing I forgot to mention earlier that is important, when creating the detail row in the onRowsChange handler, make sure you're adding all the master columns that are sortable, e.g.,
In my example, updateGridData was created via useState. |
Beta Was this translation helpful? Give feedback.
I think I have this finally resolved. I did some more digging into the data grid guts in the demo and source code and did find a good approach with sorting use a getComparator function, I followed that pattern (found it in
CommonFeatures.tsx
underwebsite\demos
) and it seems to be working fine so far. I had to tune it a bit to support my columns and data types but so far so good. My sortedRows function now looks like this: