From 4808f0edd71cea5e7c81834d6d8a2450cac91665 Mon Sep 17 00:00:00 2001 From: Allan Jardine Date: Tue, 27 Dec 2011 19:46:43 +0000 Subject: [PATCH] Dev update: Remove the 'row' event. On experimenting with CellCreated I've found that I'm getting around 4'500 triggers / sec with Safari 5.1, which really isn't close to fast enough (about two orders of magnitude out from what I would like) which means that a table with 2000 rows and 9 columns would see an additional overhead of about 4 seconds on initialisation - ouch!!! As such I've removed the 'row' event here and it would seriously impact larger tables. events are still extremely useful, however, I would suggest that plug-ins should use the callback arrays rather than events since it is much faster. These arrays might be developed further into DataTables' own triggering methods in future. Something to to be aware of certainly going into 1.10. --- media/js/jquery.dataTables.js | 26 +++++++++--------------- media/src/DataTables.js | 12 ----------- media/src/core/core.draw.js | 3 ++- media/src/core/core.support.js | 11 +++++++--- media/unit_testing/performance/large.php | 18 ++++++++-------- 5 files changed, 29 insertions(+), 41 deletions(-) diff --git a/media/js/jquery.dataTables.js b/media/js/jquery.dataTables.js index 2a4f8ce3..6cb2311f 100644 --- a/media/js/jquery.dataTables.js +++ b/media/js/jquery.dataTables.js @@ -1041,6 +1041,7 @@ } } } + } @@ -1349,7 +1350,7 @@ } /* Row callback functions - might want to manipule the row */ - _fnCallbackFire( oSettings, 'aoRowCallback', 'row', + _fnCallbackFire( oSettings, 'aoRowCallback', null, [nRow, oSettings.aoData[ oSettings.aiDisplay[j] ]._aData, iRowCount, j] ); anRows.push( nRow ); @@ -4719,10 +4720,12 @@ /** * Fire callback functions and trigger events. Note that the loop over the callback - * array store is done backwards! + * array store is done backwards! Further note that you do not want to fire off triggers + * in time sensitive applications (for example cell creation) as its slow. * @param {object} oSettings dataTables settings object * @param {string} sStore Name of the array storeage for the callbacks in oSettings - * @param {string} sTrigger Name of the jQuery customer event to trigger + * @param {string} sTrigger Name of the jQuery custom event to trigger. If null no trigger + * is fired * @param {array) aArgs Array of arguments to pass to the callback function / trigger * @memberof DataTable#oApi */ @@ -4736,7 +4739,10 @@ aRet.push( aoStore[i].fn.apply( oSettings.oInstance, aArgs ) ); } - $(oSettings.oInstance).trigger(sTrigger, aArgs); + if ( sTrigger !== null ) + { + $(oSettings.oInstance).trigger(sTrigger, aArgs); + } return aRet; } @@ -11158,18 +11164,6 @@ * @param {object} o DataTables settings object {@link DataTable.models.oSettings} */ - /** - * Row draw event, fired when a row is included in a draw - * @name DataTable#row - * @event - * @param {event} e jQuery event object - * @param {node} nRow "TR" element for the current row - * @param {array} aData Raw data array for this row - * @param {int} iDisplayIndex The display index for the current table draw - * @param {int} iDisplayIndexFull The index of the data in the full list of - * rows (after filtering) - */ - /** * DataTables initialisation complete event, fired when the table is fully drawn, * including Ajax data loaded, if Ajax data is required. diff --git a/media/src/DataTables.js b/media/src/DataTables.js index d4d10d58..9982ad36 100644 --- a/media/src/DataTables.js +++ b/media/src/DataTables.js @@ -178,18 +178,6 @@ * @param {object} o DataTables settings object {@link DataTable.models.oSettings} */ - /** - * Row draw event, fired when a row is included in a draw - * @name DataTable#row - * @event - * @param {event} e jQuery event object - * @param {node} nRow "TR" element for the current row - * @param {array} aData Raw data array for this row - * @param {int} iDisplayIndex The display index for the current table draw - * @param {int} iDisplayIndexFull The index of the data in the full list of - * rows (after filtering) - */ - /** * DataTables initialisation complete event, fired when the table is fully drawn, * including Ajax data loaded, if Ajax data is required. diff --git a/media/src/core/core.draw.js b/media/src/core/core.draw.js index 5e12eba5..5fdb2f3e 100644 --- a/media/src/core/core.draw.js +++ b/media/src/core/core.draw.js @@ -74,6 +74,7 @@ function _fnCreateTr ( oSettings, iRow ) } } } + } @@ -382,7 +383,7 @@ function _fnDraw( oSettings ) } /* Row callback functions - might want to manipule the row */ - _fnCallbackFire( oSettings, 'aoRowCallback', 'row', + _fnCallbackFire( oSettings, 'aoRowCallback', null, [nRow, oSettings.aoData[ oSettings.aiDisplay[j] ]._aData, iRowCount, j] ); anRows.push( nRow ); diff --git a/media/src/core/core.support.js b/media/src/core/core.support.js index 2d28d7a1..b95be518 100644 --- a/media/src/core/core.support.js +++ b/media/src/core/core.support.js @@ -234,10 +234,12 @@ function _fnCallbackReg( oSettings, sStore, fn, sName ) /** * Fire callback functions and trigger events. Note that the loop over the callback - * array store is done backwards! + * array store is done backwards! Further note that you do not want to fire off triggers + * in time sensitive applications (for example cell creation) as its slow. * @param {object} oSettings dataTables settings object * @param {string} sStore Name of the array storeage for the callbacks in oSettings - * @param {string} sTrigger Name of the jQuery customer event to trigger + * @param {string} sTrigger Name of the jQuery custom event to trigger. If null no trigger + * is fired * @param {array) aArgs Array of arguments to pass to the callback function / trigger * @memberof DataTable#oApi */ @@ -251,7 +253,10 @@ function _fnCallbackFire( oSettings, sStore, sTrigger, aArgs ) aRet.push( aoStore[i].fn.apply( oSettings.oInstance, aArgs ) ); } - $(oSettings.oInstance).trigger(sTrigger, aArgs); + if ( sTrigger !== null ) + { + $(oSettings.oInstance).trigger(sTrigger, aArgs); + } return aRet; } diff --git a/media/unit_testing/performance/large.php b/media/unit_testing/performance/large.php index 23d84c14..c4911528 100644 --- a/media/unit_testing/performance/large.php +++ b/media/unit_testing/performance/large.php @@ -29,19 +29,19 @@ //if ( typeof console != 'undefined' ) { // console.profile(); //} - //for ( var i=0 ; i<1 ; i++ ) - //{ - // var oTable = $('#example').dataTable({"bDestroy": true}); - //} + for ( var i=0 ; i<10 ; i++ ) + { + var oTable = $('#example').dataTable({"bDestroy": true}); + } //if ( typeof console != 'undefined' ) { // console.profileEnd(); //} - oTable.fnSort( [[ 1, 'asc' ]] ); - oTable.fnSort( [[ 1, 'asc' ]] ); - oTable.fnSort( [[ 2, 'asc' ]] ); - oTable.fnSort( [[ 1, 'asc' ]] ); - oTable.fnSort( [[ 2, 'asc' ]] ); + //oTable.fnSort( [[ 1, 'asc' ]] ); + //oTable.fnSort( [[ 1, 'asc' ]] ); + //oTable.fnSort( [[ 2, 'asc' ]] ); + //oTable.fnSort( [[ 1, 'asc' ]] ); + //oTable.fnSort( [[ 2, 'asc' ]] ); var iEnd = new Date().getTime(); document.getElementById('output').innerHTML = "Test took "+(iEnd-iStart)+" mS";