-
Notifications
You must be signed in to change notification settings - Fork 2
ajax
Karl edited this page Aug 10, 2017
·
26 revisions
Load remote data set via AJAX requst.
The easiest method is to just pass the url to the remote data and the instance will process and insert the data.
var dataTable = new DataTable(myTable, {
ajax: "some/url/data.json"
});
You can also pass an Object
with the url
and load
properties:
var dataTable = new DataTable(myTable, {
ajax: {
url: "some/url/data.json",
load: function(xhr) {
// process and/or the response data
}
}
});
The load property should return the formatted response data that the instance can recognise (Object
or JSON
). It takes a single argument which is an instance of the XMLHttpRequest
object.
var highlightNumbers = function(xhr) {
var data = JSON.parse(xhr.responseText);
for ( var i = 0; i < data.length; i++ ) {
for (var p in data[i]) {
if ( !isNaN(data[i][p]) ) {
data[i][p] = "<u style='color:red;'>" + data[i][p] + "</u>"
}
}
}
return JSON.stringify(data);
}
var dataTable = new DataTable(myTable, {
ajax: {
url: "some/url/data.json",
load: highlightNumbers
}
});
- datatable.init
- datatable.refresh
- datatable.update
- datatable.page
- datatable.sort
- datatable.perpage
- datatable.search
- ajax
- columns
- data
- firstLast
- firstText
- fixedColumns
- fixedHeight
- footer
- header
- labels
- layout
- lastText
- nextPrev
- nextText
- paging
- perPage
- perPageSelect
- prevText
- scrollY
- searchable
- sortable
- truncatePager
- table
- head DEPRECATED
- body DEPRECATED
- foot DEPRECATED
- wrapper
- container
- pagers
- headings
- options DEPRECATED
- initialized
- isIE DEPRECATED
- data
- activeRows DEPRECATED
- dataIndex
- pages
- hasRows
- hasHeadings
- currentPage
- totalPages
- onFirstPage
- onLastPage
- searching
- searchData