How to get "only" the row moved
How to get "only" the row moved
I was wondering how, with the extension row-reorder, to get the element moved only. When I move a row I get everything which was changed inside the table, but I only need the element clicked, his previous position and his new position.
If I'm asking you this is because I get the feeling that if I move an element from the top to the bottom or an element from the bottom to the bottom I get array ordered differently...
Thanks for your help ;-)
This question has an accepted answers - jump to answer
Answers
Is this in an event handler that you are looking for this data? There is no option to get only the dragged row since RowReorder implements a data swap method for row reordering - I didn't think it would be useful to have only the initial row whem multiple might have their values updated.
However, if you are using the
row-reorder
event, the data array passed in for the rows which have been reordered will always have the start (i.e. the dragged element) first in the array.Allan
Hi Allan,
Thank you for your time. In my case I use row-reorder event, and I didn't want to pass through ajax call all data and I prefer only pass the dragged element and update others (element's) position on server side.
My worry is that when I use row-reorder event, the array is not always order with the same method. I looked at https://datatables.net/extensions/rowreorder/examples/initialisation/events.html and when I dragged an element from the top to the bottom I get the element dragged at the end of the array and when I dragged an element from the bottom to the top I get the dragged element at the start of the array.
I'm not sure if I'm pretty clear with my issue :-/
Sorry - entirely my fault. I misunderstood my own code when I took at look at it this morning... What it does is to take a snapshot of the page when the mouse goes down, and then another snapshot when the mouse is released. It then spins over the two arrays and gets the difference. So yes, it is always going to be given in document order.
I can see this would be useful information, so what I've done is to commit a change that will pass that information back through to the event.
So taking the example you linked to, we could add:
and it would show the information about the trigger row.
This will be in RowReorder 1.1.0 which will be released soon, and the nightly will rebuild shortly (if it hasn't already :-) ) with this change.
Allan
That's really really good to hear allan, many thanks to you ;-)