preInit
Initialisation started event - triggered immediately before data load.
Description
This event is emitted by DataTables when a table is being initialised and is about to request data. At the point of being fired the table will have its columns and features initialised, but no data will have been loaded (either by Ajax, or reading from the DOM).
Its primary purpose is to allow authors of extensions to DataTables be add a listener to the document so some action can be taken before data is loaded (for example modifying the amount of data to be loaded).
Please note that, as with all DataTables emitted events, the event object has a DataTables API instance available on it (the first parameter). Additionally, the events are triggered with the dt
namespace. As such, to listen for this event, you must also use the dt
namespace by simply appending .dt
to your event name, as shown in the example below.
Type
function function( e, settings )
- Parameters:
Name Type Optional 1 e
No jQuery event object
2 settings
No DataTables settings object
Example
Set the data length to display to be 20 items:
$(document).on('preInit.dt', function (e, settings) {
var api = new DataTable.Api(settings);
api.page.len(20);
});
new DataTable('#myTable');
Related
The following options are directly related and may also be useful in your application development.