Using ag-grid column moving inside a group (https://www.ag-grid.com/javascript-grid-column-moving/) works as intended, but after collapsing this group order is not preserved, initial first column is shown, not the first column after the move. You can see it as default behavior (https://www.ag-grid.com/example.php). Column API method setColumnGroupOpened
is used for expand / collapse of a group (you can find it here https://www.ag-grid.com/javascript-grid-column-api/).
Steps:
Have a group of columns
Replace the first column with the second by moving feature (by drag'n'drop or api)
Collapse this group
You can reproduce it in the official example https://www.ag-grid.com/example.php.
Actual result: initial first column is shown, not the moved one.
Desired result: moved one column is shown after collapse.
There are few possible solutions, but they seemed doubtful and not really clean. There could be an algorithm mutating column or group definition columnGroupShow
field in needed way. The field is documented here: https://www.ag-grid.com/javascript-grid-column-properties/. The algorithm can be executed on columnnMoved
or expand / collapse event. Columns with preserved order should be involved in this manipulation. Column API method for this purpose is getAllGridColumns
. Using it with event payload becomes not really handy, all columns in the tree should be checked and columnGroupShow
field should be updated where needed.
What is the proper / recommended way to reach such a behavior?