Reputation:
I am having a problem with jQuery Datatables, just added rowReorder
option to my table, the problem is that when I drag and drop the selected row it moves only by one row. The option that I used was:
rowReorder: true,
Example: https://jsfiddle.net/4gfh00u8/
Tried looking at the documentation or answers but didn't find a solution.
Upvotes: 4
Views: 2308
Reputation: 6054
The solution is rowReorder.update, as the docs say:
By default RowReorder will [...] redraw the table to account for any changes in ordering.
This action is not always desirable, particularly if you are using server-side processing or wish to have an external process update the data
So we can disable the update and handle the reordering event (storing the new ordering to db) with a custom function (with table.on('row-reorder')
):
"rowReorder": {
dataSrc: 5, // hidden column, it contains the object id
update: false
},
Upvotes: 2
Reputation: 58880
You need to have a column or data property with a sequence number. By default, RowReorder extension is looking for it in the first column.
In the basic initialization example, it says:
The first column in the table is a sequence number that provides the basis for the ordering.
If you don't want to display sequence number in the table, you can also specify data source for sequence number with rowReorder.dataSrc
.
There are couple other issues with your code, for example, ordering should not be disabled with order: false
. Also there is a typo in columnDefs
option name.
See updated example for code and demonstration.
Upvotes: 2