Pedro Silveira
Pedro Silveira

Reputation: 342

Ag-grid drag and drop doesn't work after sorting rows

After sorting my rows on Ag-grid-react, drag and drop stops working. Before sorting, drag and drop is all set and working well.

postSort API does not seem to have something to achieve what I need, reset the row or even set draggable just like for selection.

postSort={nodes => nodes.forEach(n => n.setRowSelectable(true))}

I've tried also to use

postSort={nodes => nodes.forEach(n => n.setDragging(true))}

but that would actually start the dragging for all the rows instead

I want the drag and drop to keep working when row is clicked after sorting them. Thanks in advance!

Upvotes: 2

Views: 2287

Answers (2)

Zohar
Zohar

Reputation: 153

I found a solution that worked for me. if you are facing a similar issue where you want to enable drag after a sort you need to disable the sort like this:

gridColumnApi.applyColumnState({ defaultState: { sort: null } });

this will bring back the drag&drop to the columns you had it prior to the sort.

Still trying to find a way to tell the grid to reorganize its indexes so we can keep the sort and enable the drag at the same time.

Upvotes: 2

NearHuscarl
NearHuscarl

Reputation: 81340

If you are using Managed Dragging (rowDragManaged={true}), you cannot drag any rows anywhere else because doing that will break the order of the rows as stated in the docs

The logic for managed dragging is simple and has the following constraints:

  • Does not work when sorting is applied. This is because the sort order of the rows depends on the data and moving the data would break the sort order.

Upvotes: 1

Related Questions