row-reorder
Rows have been reordered by the end user.
Please note - this property requires the RowReorder extension for DataTables.
Description
When using RowReorder you will likely wish to know when a table has been reordered by an end user so you can update a data store to reflect these changes. This event provides that ability.
The data that has been changed by RowReorder is given in two different forms in the parameters for the event handler callback - one with detailed information about the individual rows, and one with data in a format suitable for Editor's multi-row editing feature.
This event is triggered when a row is dropped, but prior to the new data being written to the database.
As of RowReorder 1.4.1 this event is cancellable by returning false
from the event handler function. If there are multiple event handlers, the last non-undefined
return value will be used as the return value after all event handlers have been executed in order.
Please note that, as with all DataTables emitted events, this event is triggered with the dt
namespace. As such, to listen for this event, you must also use the dt
namespace by simply appending .dt
to your event name, or use the on()
method to listen for the event which will automatically append this namespace.
Type
function function( e, details, edit )
- Parameters:
Name Type Optional 1 e
No jQuery event object
2 details
No An array of change objects for the row's how have had values effected. Each object contain the following properties:
Any
newData
- The new data value for the row (data point defined byrowReorder.dataSrc
)node
node
- Thetr
elementinteger
newPosition
- New index in the DOMAny
oldData
- The old data value for the rowinteger
oldPosition
- Old index in the DOM
3 edit
No This parameter provides the information required for Editor to perform a multi-row edit:
string
dataSrc
- Data point - typically the field to be edited (defined byrowReorder.dataSrc
)array
nodes
- The rows to be editedobject
values
- The new values in a format suitable formultiSet()
.DataTable.Api
triggerRow
(Since v1.1.0) - Row API instance for the row that was used to start the reorder (i.e. the result fromrow()
).object
originalEvent
(Since v1.2.6) - The original event (mouseup) that triggered the reorder.
Examples
Add a class to all changed rows:
var table = new DataTable('#myTable', {
rowReorder: true
});
table.on('row-reorder', function (e, diff, edit) {
for (var i = 0, ien = diff.length; i < ien; i++) {
$(diff[i].node).addClass('reordered');
}
});
Use Editor's multi-row editing to update a database on row reorder:
table.on('row-reorder', function (e, details, changes) {
editor
.edit(changes.nodes, false, {
submit: 'changed'
})
.multiSet(changes.dataSrc, changes.values)
.submit();
});