When loading data from an Ajax source, by default, DataTables will look for the data to use in the
data
parameter of a returned object (e.g. { "data": [...] }
). Using the
dataSrc
option of the ajax
initiation option
you can easily tell DataTables to look for something else.
The ajax.dataSrc
has a number of ways in which it can be used:
dataSrc: 'myData'
) - obtain data from a different property in the source
object.dataSrc: ''
) - the data source is not an object but an
array.dataSrc: function(json) {}
) - a function can be used to transform the
data from one source format to another (for example you could convert from XML to a Javascript object). The
value returned from the function is used as the data for the table.The example below shows ajax.dataSrc
being used as a string to get the data from a different
source property.
Name | Age | Position | Office | Start date | Salary |
---|---|---|---|---|---|
Name | Age | Position | Office | Start date | Salary |