fnDeleteRow slow on massive updates (patch)
fnDeleteRow slow on massive updates (patch)
Hi.
I needed to do removal of many rows (order of tens) and it seems that dataTables does removal very slow because in redraws table at every call to fnDeleteRow.
Here is very simple patch which allows to prevent table redraw:
--- a/static/jquery.dataTables.js
+++ b/static/jquery.dataTables.js
@@ -1357,7 +1357,7 @@
* would mess up all the subsequent indexes in the display arrays (they could be ajusted -
* but this appears to do what is required).
*/
- this.fnDeleteRow = function( mTarget, fnCallBack, bNullRow )
+ this.fnDeleteRow = function( mTarget, fnCallBack, bNullRow, bNoRedraw )
{
/* Find settings from table node */
var oSettings = _fnSettingsFromNode( this[_oExt.iApiIndex] );
@@ -1405,9 +1405,10 @@
}
}
+ if(!bNoRedraw) {
_fnCalculateEnd( oSettings );
_fnDraw( oSettings );
-
+ }
/* Return the data array from this row */
var aData = oSettings.aoData[iAODataIndex]._aData.slice();
If bNoRedraw is true then no redraw will happen. One just needs to call fnDraw after all removals are completed.
Hope this helps and hope this feature will be included in future versions.
Thanks.
I needed to do removal of many rows (order of tens) and it seems that dataTables does removal very slow because in redraws table at every call to fnDeleteRow.
Here is very simple patch which allows to prevent table redraw:
--- a/static/jquery.dataTables.js
+++ b/static/jquery.dataTables.js
@@ -1357,7 +1357,7 @@
* would mess up all the subsequent indexes in the display arrays (they could be ajusted -
* but this appears to do what is required).
*/
- this.fnDeleteRow = function( mTarget, fnCallBack, bNullRow )
+ this.fnDeleteRow = function( mTarget, fnCallBack, bNullRow, bNoRedraw )
{
/* Find settings from table node */
var oSettings = _fnSettingsFromNode( this[_oExt.iApiIndex] );
@@ -1405,9 +1405,10 @@
}
}
+ if(!bNoRedraw) {
_fnCalculateEnd( oSettings );
_fnDraw( oSettings );
-
+ }
/* Return the data array from this row */
var aData = oSettings.aoData[iAODataIndex]._aData.slice();
If bNoRedraw is true then no redraw will happen. One just needs to call fnDraw after all removals are completed.
Hope this helps and hope this feature will be included in future versions.
Thanks.
This discussion has been closed.
Replies
Awesome - thanks very much for this patch. Looks good to me - and yup - I'll include this in the next release of DataTables :-)
Regards,
Allan
UPDATE: Nevermind already implemented in latest download... just had to upgrade.
[code]
var rows = this.fnGetNodes();
for (var i = 0; i < rows.length; i++) {
if ($(rows[i]).hasClass('row_selected')) {
this.fnDeleteRow(rows[i], null, false);
}
}
this.fnDraw();
[/code]
Just remember to this.fnDraw(); after all the deleting.