From f702ac564896b853252252039a776afb8d715ea3 Mon Sep 17 00:00:00 2001 From: Allan Jardine Date: Mon, 2 Jan 2012 10:19:19 +0000 Subject: [PATCH] New: Allow state loading to be cancelled from the aoStateLoadParams callbacks by returning false (matches the capabilities of the old state loading methods) --- media/js/jquery.dataTables.js | 20 ++++++++++++++++++-- media/src/core/core.state.js | 10 ++++++++-- media/src/model/model.defaults.js | 10 ++++++++++ 3 files changed, 36 insertions(+), 4 deletions(-) diff --git a/media/js/jquery.dataTables.js b/media/js/jquery.dataTables.js index 21bccd3a..3afb9a7c 100644 --- a/media/js/jquery.dataTables.js +++ b/media/js/jquery.dataTables.js @@ -4277,8 +4277,14 @@ return; } - /* Allow custom and plug-in manipulation functions to alter the saved data set */ - _fnCallbackFire( oSettings, 'aoStateLoadParams', 'stateLoadParams', [oSettings, oData] ); + /* Allow custom and plug-in manipulation functions to alter the saved data set and + * cancelling of loading by returning false + */ + var abStateLoad = _fnCallbackFire( oSettings, 'aoStateLoadParams', 'stateLoadParams', [oSettings, oData] ); + if ( $.inArray( false, abStateLoad ) !== -1 ) + { + return; + } /* Store the saved state so it might be accessed at any time */ oSettings.oLoadedState = $.extend( true, {}, oData ); @@ -8343,6 +8349,16 @@ * oData.oFilter.sSearch = ""; * } ); * } ); + * + * @example + * // Disallow state loading by returning false + * $(document).ready(function() { + * $('#example').dataTable( { + * "bStateSave": true, + * "fnStateLoadParams": function (oSettings, oData) { + * return false; + * } ); + * } ); */ "fnStateLoadParams": null, diff --git a/media/src/core/core.state.js b/media/src/core/core.state.js index fa8b80b3..b9a28be1 100644 --- a/media/src/core/core.state.js +++ b/media/src/core/core.state.js @@ -55,8 +55,14 @@ function _fnLoadState ( oSettings, oInit ) return; } - /* Allow custom and plug-in manipulation functions to alter the saved data set */ - _fnCallbackFire( oSettings, 'aoStateLoadParams', 'stateLoadParams', [oSettings, oData] ); + /* Allow custom and plug-in manipulation functions to alter the saved data set and + * cancelling of loading by returning false + */ + var abStateLoad = _fnCallbackFire( oSettings, 'aoStateLoadParams', 'stateLoadParams', [oSettings, oData] ); + if ( $.inArray( false, abStateLoad ) !== -1 ) + { + return; + } /* Store the saved state so it might be accessed at any time */ oSettings.oLoadedState = $.extend( true, {}, oData ); diff --git a/media/src/model/model.defaults.js b/media/src/model/model.defaults.js index fb0e4a62..535687fa 100644 --- a/media/src/model/model.defaults.js +++ b/media/src/model/model.defaults.js @@ -988,6 +988,16 @@ DataTable.defaults = { * oData.oFilter.sSearch = ""; * } ); * } ); + * + * @example + * // Disallow state loading by returning false + * $(document).ready(function() { + * $('#example').dataTable( { + * "bStateSave": true, + * "fnStateLoadParams": function (oSettings, oData) { + * return false; + * } ); + * } ); */ "fnStateLoadParams": null,