Rowreorder with unordered sequence...
Rowreorder with unordered sequence...
Hi, I'm trying to use Rowreorder and noticed in one of the examples[1], that if I order a column, the information reported at the top of the table is incorrect, and the reorder is not allowed. For example:
- Order by Start Date (asc)
- Move Seq #14 (Charde Marshall) to the top and replace Seq #34 (Jackson Bradshaw)
Results say:
Reorder started on row: Charde Marshall
Charde Marshall updated to be in position 34 (was 14)
Jackson Bradshaw updated to be in position 14 (was 34)
So although the sequence updated, the other data remains. I would like to have the entire row swapped if possible, even though the sequence is out of order, so I'm not sure this is expected behaviour or not?
[1]https://datatables.net/extensions/rowreorder/examples/initialisation/events.html
This question has an accepted answers - jump to answer
Answers
Okay, so the data swap is not the entire row, but the column index defined by rowReorder: { dataSrc: 0 } (in my case the first column.)
There is an example[1] which uses two columns to do this, but is that the only way to do it?....
[1] https://datatables.net/forums/discussion/46889/row-reordering-after-sorting
It is. The behaviour you are looking for - just swapping the DOM elements, is not something that RowReorder offers. For that you could look at using a library such as jQuery UI Sortable.
DataTables always uses data for sorting, hence the use of the data-swap method in RowReorder.
Allan
Thanks @allan , after googling Jquery UI, I see this is a regular question- sorry.
I had a fiddle with Jquery-UI, and that does indeed swap the DOM elements (and a hidden data-src parameter I attach to each row), but the order is not preserved with pagenation, nor reordering another column.
From what I can see, the way for using only DataTables is to have another (hidden) column set as the rowReorder: dataSrc, and update the dataSrc column in sequential order after events such as row-reordered...