mirror of
https://github.com/DataTables/DataTables.git
synced 2025-03-15 16:29:16 +01:00
New - API: Static on()
method, which listens for static events from DataTables
- Some plug-ins would benefit from be able to automatically initialise when a DataTables is constructed, to this end, a construct for static events is added here, with the static function $.fn.dataTable.on() listening for events. Currently only the `construct` method is available, although others could potentially be added in future if they are useful. As such, the code driving it is intentionally simple for this cas,e but the API abstract enough to allow future expansion. - There is no `off()` method, as I'm not sure it would be that useful. Could be added in future if needed!
This commit is contained in:
parent
4e05760b20
commit
846c4d9c60
@ -1 +1 @@
|
||||
ba7b99443fcd45f1ab7555e046188ee7cd559eb3
|
||||
ddd0e5f5c9509cd8fa5630453cc05c9f68863644
|
||||
|
35
media/js/jquery.dataTables.js
vendored
35
media/js/jquery.dataTables.js
vendored
@ -2731,6 +2731,10 @@
|
||||
}
|
||||
|
||||
_fnCallbackFire( settings, 'aoInitComplete', 'init', [settings, json] );
|
||||
|
||||
$.each( DataTable._initQueue, function ( i, fn ) {
|
||||
fn( settings );
|
||||
} );
|
||||
}
|
||||
|
||||
|
||||
@ -8140,7 +8144,7 @@
|
||||
* @dtopt API-Static
|
||||
*
|
||||
* @example
|
||||
* $.each( $.fn.dataTable.fnTables(true), function () {
|
||||
* $.each( $.fn.dataTable.tables(true), function () {
|
||||
* $(table).DataTable().columns.adjust();
|
||||
* } );
|
||||
*/
|
||||
@ -8158,6 +8162,35 @@
|
||||
};
|
||||
|
||||
|
||||
// Private property used for sorting the construct event listeners
|
||||
DataTable._initQueue = [];
|
||||
|
||||
/**
|
||||
* Listen for a static event from DataTables. Currently only one event is
|
||||
* available: `construct` which is fired whenever a new table is created. This
|
||||
* is for plug-ins to be able to automatically initialise themselves when a
|
||||
* table is created.
|
||||
*
|
||||
* @param {string} ev Event to listen for. Currently only `construct` is
|
||||
* available.
|
||||
* @param {function} fn Function to be executed on event occurrence. A single
|
||||
* parameter is passed in, the settings object for the new table.
|
||||
* @static
|
||||
* @dtopt API-Static
|
||||
*
|
||||
* @example
|
||||
* $.fn.dataTable.on( 'construct', function ( settings ) {
|
||||
* alert( 'A new table was created' );
|
||||
* } );
|
||||
*/
|
||||
DataTable.on = function ( ev, fn )
|
||||
{
|
||||
if ( ev === 'construct' ) {
|
||||
DataTable._initQueue.push( fn );
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
(/** @lends <global> */function() {
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user