Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 49 additions & 1 deletion js/dataTables.rowReorder.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,15 @@ $.extend( RowReorder.prototype, {
return false;
}
} );

// check if sorting should reorder data
// if it should reorder, then it adds listener for sorting, and when data has been
// sorted, it updates data with new row numbers.
if (that.c.reorderOnSort) {
$( table ).on( 'order.dt', function (e, table, sort) {
that._ReNumerate();
});
}

dt.on( 'destroy', function () {
table.off( 'mousedown.rowReorder' );
Expand Down Expand Up @@ -256,6 +265,32 @@ $.extend( RowReorder.prototype, {
left: left
} );
},

/**
* Update the items position based on new order
*
* @private
*/
_ReNumerate: function ()
{
var i, ien,
dt = this.s.dt;

// Calculate the difference
var Nodes = $.unique(dt.rows().nodes().toArray());

var getDataFn = this.s.getDataFn;
var setDataFn = this.s.setDataFn;

for ( i=0, ien=Nodes.length ; i<ien ; i++ ) {

var rowData = dt.row( Nodes[i] ).data();
setDataFn(rowData, i);

var row = dt.row(Nodes[i]);
row.invalidate('data');
}
},


/**
Expand Down Expand Up @@ -304,6 +339,12 @@ $.extend( RowReorder.prototype, {
var that = this;
var dt = this.s.dt;
var start = this.s.start;

//if the table has been reordered on sorting, then this will set the sorting
//to new column order when dragging and dropping rows
if (this.c.reorderOnSort) {
dt.order([0,'asc']);
}

var offset = target.offset();
start.top = this._eventToPage( e, 'Y' );
Expand Down Expand Up @@ -547,7 +588,14 @@ RowReorder.defaults = {
*
* @type {Boolean}
*/
update: true
update: true,

/**
* Update the sequence on sorting
*
* @type {Boolean}
*/
reorderOnSort: false
};


Expand Down