File: xhr.xml

package info (click to toggle)
datatables.js 1.10.19%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 6,348 kB
  • sloc: xml: 10,397; php: 4,448; sh: 521; makefile: 21
file content (68 lines) | stat: -rw-r--r-- 3,449 bytes parent folder | download | duplicates (3)
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?xml version="1.0" encoding="UTF-8" ?>
<dt-event>
	<name>xhr</name>
	<summary>Ajax event - fired when an Ajax request is completed</summary>
	<since>1.10</since>

	<type type="function">
		<signature>function( e, settings, json, xhr )</signature>
		<parameter type="object" name="e">
			jQuery event object
		</parameter>
		<parameter type="DataTables.Settings" name="settings">
			DataTables settings object
		</parameter>
		<parameter type="object" name="json">
			Data returned from the server. This will be `-type null` if triggered by the Ajax error callback.
		</parameter>
		<parameter type="object" name="xhr" since="1.10.7">
			[jQuery XHR](http://api.jquery.com/Types/#jqXHR) object that can be used to access the low level Ajax options.
		</parameter>
		<return type="boolean">
			Since 1.10.7 you can return `true` to indicate to DataTables that it should not trigger its `dt-event error` event if you have handled an error condition yourself.
		</return>
		<scope>HTML table element</scope>
	</type>

	<description>
		When working with Ajax data, it is often useful to know when DataTables has completed the loading of data, so you can either manipulate that data into the format DataTables expects based upon its configuration (`dt-init columns.data`) or so you can use the data contained in the JSON response from the server for other parts of the page.

		This event can be seen as the event compliment to the `dt-init ajax.dataSrc` option (which can also be used to manipulate and intercept the data from the Ajax request). Generally you would want to do data manipulation in the `dataSrc` callback and use events for intercepting the data.

		Note that this event is called before DataTables has processed the new data from the server, so the returned data will not have been drawn on page when this event fires.

		Additionally, as of DataTables 1.10.7 this event is triggered by both success and error conditions when the Ajax request completed (i.e. it is always triggered regardless of the outcome of the Ajax request). Prior to 1.10.7 it was only triggered by a successful request. The `json` parameter (3th passed in) for the event handler will be `null` if an error has occurred and the `xhr` parameter (4th) can be used to determine the error details if required.

		Please note that, as with all DataTables emitted events, this event is 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.
	</description>

	<example title="Pre-process the data returned from the server"><![CDATA[
$('#example')
	.on('xhr.dt', function ( e, settings, json, xhr ) {
		for ( var i=0, ien=json.aaData.length ; i<ien ; i++ ) {
			json.aaData[i].sum = json.aaData[i].one + json.aaData[i].two;
		}
		// Note no return - manipulate the data directly in the JSON object.
	} )
	.dataTable( {
		ajax: "data.json"
	} );
]]></example>

	<example title="Use a custom property returned from the server in another DOM element"><![CDATA[
$('#example')
	.on('xhr.dt', function ( e, settings, json, xhr ) {
		$('#status').html( json.status );
	} )
	.dataTable( {
		ajax: "data.json"
	} );

]]></example>

	<related type="option">ajax</related>
	<related type="api">ajax.json()</related>
	<related type="api">ajax.url()</related>
	<related type="api">ajax.reload()</related>
	<related type="event">preXhr</related>
</dt-event>