Describe the bug
Updating the data of a table resets any sorting.
To Reproduce
Steps to reproduce the behavior:
Expected behavior
I want the table to keep the sorting when updating the data.
Additional context
I think this behaviour was introduce at version 1.62.0 with this commit
FYI I see the same thing but with a simple resize event...
Same issue here. Wondering if there is any update on this issue? Thank you!
I'm also having this problem, +1
Definitely seeing this issue too. Running material-table v1.68.0. ANY updates that cause a component render (like updating state via useState hook) will trigger this defect.
Same issue with v1.68.1
I also see this problem, especially annoying since it makes using sorting and selecting at the same time not usable when using state to track selection changes.
Also having this problem
@mbrn what are your thoughts on this issue ?
Hey guys I fixed this by using a workaround. Long story short, what I did was:
tableRef of the MaterialTable componenttableRef.current.state. If the default sorting changed, save the orderBy and orderDirection values to a local ref.I hope this helps anyone. I know it might be a bit confusing but I'll let you with this for now. Maybe I find some time to put an example together somewhere.
I also have this issue, it's very annoying. Downgrading until this is fixed. Hope to see a fix soon.
Hey guys I fixed this by using a workaround. Long story short, what I did was:
- Save the
tableRefof theMaterialTablecomponent- Right before you update the data, check the
tableRef.current.state. If the default sorting changed, save theorderByandorderDirectionvalues to a local ref.- Also if the default sorting changed, pass these values to the parent component via a callback. The parent should then update the columns array that it passes to the component containing the MaterialTable component, with the new sorting values. By updating I mean updating the state of the columns. For this, you will need to save the columns to the component's state.
I hope this helps anyone. I know it might be a bit confusing but I'll let you with this for now. Maybe I find some time to put an example together somewhere.
@gtupak , do you have any example for it
Most helpful comment
FYI I see the same thing but with a simple resize event...