fnDeleteRow slow on massive updates (patch)

fnDeleteRow slow on massive updates (patch)

kolyakolya Posts: 4Questions: 0Answers: 0
edited March 2010 in General
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.

Replies

  • allanallan Posts: 63,535Questions: 1Answers: 10,475 Site admin
    Hi kolya,

    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
  • kalakudukalakudu Posts: 3Questions: 0Answers: 0
    very cool!
  • krefftckrefftc Posts: 1Questions: 0Answers: 0
    edited November 2011
    Can someone explain how i can apply this patch?

    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.
This discussion has been closed.