File: ajax.dataSrc.xml

package info (click to toggle)
datatables.js 1.10.13%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 6,232 kB
  • ctags: 1,329
  • sloc: xml: 10,249; php: 4,387; sh: 492; makefile: 21
file content (74 lines) | stat: -rw-r--r-- 3,386 bytes parent folder | download | duplicates (2)
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
69
70
71
72
73
74
<?xml version="1.0" encoding="UTF-8" ?>
<dt-option group="data">
	<name>ajax.dataSrc</name>
	<summary>Data property or manipulation method for table data</summary>
	<since>1.10</since>

	<type type="string">
		<description>
			As a string, `dataSrc` defines the property from the data source object (i.e. that returned by the Ajax request) to read.

			Note that if your Ajax source simply returns an array of data to display, rather than an object, set this parameter to be an empty string.

			Additionally you can use Javascript dotted object notation to get a data source for multiple levels of object / array nesting.
		</description>
	</type>

	<type type="function">
		<signature>ajax.dataSrc( data )</signature>
		<parameter type="object" name="data">
			Data returned from the server for the Ajax request
		</parameter>
		<returns type="array">
			Array of data that DataTables is to use to draw the table
		</returns>
		<description>
			As a function `dataSrc` provides the ability to manipulate the data returned from the server from one form into another. For example, if your data is split over multiple arrays you might combine it into a single array to return for processing and display by DataTables.

			In this form `dataSrc` can be used to transform any data source, such as non-JSON data (XML, YAML, etc) into the Javascript array that DataTables expects.
		</description>
	</type>

	<description>
		The `dt-init ajax` option basically inherits all of the options made available by [jQuery.ajax](http://api.jquery.com/jQuery.ajax/), but we provide the extra option of `dataSrc` to provide the ability to alter what data DataTables will read from the JSON return from the server, or to manipulate the data from one form into another (be it JSON to another form of JSON, XML, YAML etc). This is done because the `success` option of `dt-init ajax` **should not** be altered - DataTables uses it internally to execute the table draw when the data load is complete.
	</description>

	<default>`dt-string data` property of the data source object (or `dt-string aaData` if `dt-string data` is not present for backwards compatibility).</default>

	<example title="Get JSON data from a file via Ajax, using `dataSrc` to change `data` to `tableData` (i.e. `{ tableData: [ ...data... ] }`)"><![CDATA[
$('#example').dataTable( {
  "ajax": {
    "url": "data.json",
    "dataSrc": "tableData"
  }
} );
]]></example>

	<example title="Get JSON data from a file via Ajax, using `dataSrc` to read data from a plain array rather than an array in an object"><![CDATA[
$('#example').dataTable( {
  "ajax": {
    "url": "data.json",
    "dataSrc": ""
  }
} );
]]></example>

	<example title="Manipulate the data returned from the server - add a link to data (note this can, should, be done using `render` for the column - this is just a simple example of how the data can be manipulated)."><![CDATA[
$('#example').dataTable( {
  "ajax": {
    "url": "data.json",
    "dataSrc": function ( json ) {
      for ( var i=0, ien=json.data.length ; i<ien ; i++ ) {
        json.data[i][0] = '<a href="/message/'+json.data[i][0]+'>View message</a>';
      }
      return json.data;
    }
  }
} );
]]></example>

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