When using the RowReorder feature in a TreeGrid, how do I get the source index of a reordered row?
Say that I have a list of records: [3,4,5]
And I am moving the record 3 to be the last record: [4,5,3]
The source index is 0 and the target index is 2.
Is there any value in the context object provided by the gridRowDrop listener which gives me the source index (in this case 0)?
The backend is expecting an integer which indicates how many positions a record should move. To compute that integer, I need to know the source index and the target index.
Re: [REACT] Get the source index of a reordered row
Re: [REACT] Get the source index of a reordered row
Posted: Thu Nov 25, 2021 12:50 pm
by Yamo1993
Thanks, I will try that.
Re: [REACT] Get the source index of a reordered row
Posted: Thu Nov 25, 2021 2:25 pm
by Yamo1993
I tried to listen for "move", but the event doesn't seem to trigger when rows are reordered. I then tried to listen for "change", and all I see are the events "add", "remove", "removeall" and "update".
I should add that I have implemented a custom data handling for the grid, where I always update the store with a new dataset by running "store.removeAll()" and then "store.add(data)" when the React state changes. This was necessary since the grid doesn't update correctly when the dataset changes.
Could it be that the event is never triggered since the data store is completely updated?
Re: [REACT] Get the source index of a reordered row
Posted: Thu Nov 25, 2021 2:46 pm
by Animal
The event works here when I move a row in the grid:
Screenshot 2021-11-25 at 13.45.12.png (338.32 KiB) Viewed 933 times
Re: [REACT] Get the source index of a reordered row
Posted: Thu Nov 25, 2021 2:47 pm
by Animal
Update the whole dataset?
That should not be necessary. Records all inform their store when their fields are mutated, and the Store then fires an event.
Re: [REACT] Get the source index of a reordered row
Posted: Thu Nov 25, 2021 2:57 pm
by saki
The move event should fire as long as you listen to it before you update data. Just to make sure, you have installed the listener on the store, haven't you?
move-event.gif (265.05 KiB) Viewed 933 times
Re: [REACT] Get the source index of a reordered row
Posted: Thu Nov 25, 2021 5:26 pm
by Yamo1993
The "move" event is not triggered when using a TreeGrid. It only gets triggered when the tree feature is off.