Skip to content

Speed up col reorder call #57

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 9, 2016
Merged
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
25 changes: 19 additions & 6 deletions js/dataTables.colReorder.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,15 @@ function fnDomSwitch( nParent, iFrom, iTo )
* @param int iTo and insert it into this point
* @param bool drop Indicate if the reorder is the final one (i.e. a drop)
* not a live reorder
* @param bool invalidateRows speeds up processing if false passed
* @returns void
*/
$.fn.dataTableExt.oApi.fnColReorder = function ( oSettings, iFrom, iTo, drop )
$.fn.dataTableExt.oApi.fnColReorder = function ( oSettings, iFrom, iTo, drop, invalidateRows )
{
var i, iLen, j, jLen, jen, iCols=oSettings.aoColumns.length, nTrs, oCol;
if(typeof(invalidateRows) === 'undefined') {
invalidateRows = true;
}
var attrMap = function ( obj, prop, mapping ) {
if ( ! obj[ prop ] || typeof obj[ prop ] === 'function' ) {
return;
Expand Down Expand Up @@ -328,9 +332,9 @@ $.fn.dataTableExt.oApi.fnColReorder = function ( oSettings, iFrom, iTo, drop )
}
}

// Invalidate row cached data for sorting, filtering etc
var api = new $.fn.dataTable.Api( oSettings );
api.rows().invalidate();
if(invalidateRows === true) {
this.oApi.fnColRowsInvalidate();
}

/*
* Update DataTables' event handlers
Expand Down Expand Up @@ -358,6 +362,13 @@ $.fn.dataTableExt.oApi.fnColReorder = function ( oSettings, iFrom, iTo, drop )
} ] );
};

$.fn.dataTableExt.oApi.fnColRowsInvalidate = function ( oSettings )
{
// Invalidate row cached data for sorting, filtering etc
var api = new $.fn.dataTable.Api( oSettings );
api.rows().invalidate();
};


/**
* ColReorder provides column visibility control for DataTables
Expand Down Expand Up @@ -778,12 +789,14 @@ $.extend( ColReorder.prototype, {
fnArraySwitch( a, currIndex, i );

/* Do the column reorder in the table */
this.s.dt.oInstance.fnColReorder( currIndex, i, true );
this.s.dt.oInstance.fnColReorder( currIndex, i, true, false );

changed = true;
}
}

this.s.dt.oInstance.fnColRowsInvalidate();

this._fnSetColumnIndexes();

// Has anything actually changed? If not, then nothing else to do
Expand All @@ -799,7 +812,7 @@ $.extend( ColReorder.prototype, {

/* Save the state */
this.s.dt.oInstance.oApi._fnSaveState( this.s.dt );

if ( this.s.reorderCallback !== null )
{
this.s.reorderCallback.call( this );
Expand Down