1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
|
<?xml version="1.0" encoding="UTF-8" ?>
<dt-api group="core">
<name>one()</name>
<summary>Listen for a table event once and then remove the listener.</summary>
<since>1.10</since>
<type type="function">
<signature>one( event, callback )</signature>
<description>Add an event listener, for which the callback will be fired once only and then the event listener removed.</description>
<parameter type="string" name="event">
Event to listen for. Multiple events can be listened for using a space separator and events can be namespaced, just like with `jQuery().on()`.
</parameter>
<parameter type="function" name="callback">
Event callback handler. For the argument list passed in, please refer to the documentation for the event that you are using.
</parameter>
<returns type="DataTables.Api">DataTables API instance</returns>
</type>
<description>
DataTables can trigger a number of events which can be useful for taking action when DataTables performs those events. For example, it is often useful to know when an Ajax event occurs (`dt-event xhr`), so you can add additional data to the JSON payload.
DataTables provides three methods for working with DataTables events, matching the core jQuery event methods:
* `dt-api on()` - Listen for events
* `dt-api off()` - Stop listening for events
* `dt-api one()` - Listen for a single event.
This `dt-api one()` method is used to listen for DataTables an event from DataTables and then immediately remove that event once it has fired for the first time. Simply pass in the event you wish to listen for an provide a callback function which will be activated, and then removed, when the event is triggered by DataTables.
</description>
<example title="Listen for only the first `dt-event xhr` event from DataTables"><![CDATA[
var table = $('#example').DataTable( {
ajax: "/data",
serverSide: true
} );
table.one( 'xhr', function ( e, settings, json ) {
console.log( 'Ajax event occurred. Returned data: ', json );
} );
]]></example>
<related type="api">on()</related>
<related type="api">off()</related>
</dt-api>
|