How to persist ordering of fields in MUI Datagrid premium / pro?
onColumnOrderChange
gives only the last moved column
apiRef.current.getAllColumns()
or apiRef.current.state.columns.orderedFields
gives array of fields the way they are visible at the moment. But that is not their original position.
Right pinned columns are stored at the end of those arrays, but their actual position is not at the end.
When I unpin a column, it moves to its original position. Where those positions are kept?
Example:
columns = [col1, col2, col3]
pinnedColumns={right: [col2]}
...
const apiRef = useGridApiRef()
apiRef.current.getAllColumns() // gives [col1, col3, col2] the way they are visible. col2 pinned right
When I unpin col2
, apiRef.current.getAllColumns()
gives [col1, col2, col3]
Actually col2
never changes its position, it is always on the second place. But apiRef.current.getAllColumns()
does not give the original positions. It is only visible as the most right, because it is pinned. How the datagrid knows where to restore it on unpin? Where that information is kept? I want to save that ordering so I can use it to initialize the datagrid on next mount.
Datagrid premium version 5.17