The reason the remote isn't working is because when fetching data via AJAX, the response JSON must have some meta-data included with it along with the actual records.
If you look at the AJAX example in the dynatable docs, you can click "View AJAX Data" to see what the format looks like:
{
"records": [
{
"someAttribute": "I am record one",
"someOtherAttribute": "Fetched by AJAX"
},
{
"someAttribute": "I am record two",
"someOtherAttribute": "Cuz it's awesome"
},
{
"someAttribute": "I am record three",
"someOtherAttribute": "Yup, still AJAX"
}
],
"queryRecordCount": 3,
"totalRecordCount": 3
}
You can see the actual results array is nested under "records"
in the response JSON, and it also returns how many records are total in the set, as well as how many are in the current set.
The reason this meta-data is needed by dynatable is in order to do the pagination and the record-count text at the bottom of the table. Since your server is doing the actual querying, sorting, and paginating (e.g. via a database query or other server-side processing), dynatable only sees the final result. Therefore, dynatable wouldn't ever know:
how many total records are in the set vs.
how many records are in the filtered/queried set (across all pages) vs.
how many records are in the filtered/queried paginated set (on the current page).
The only thing dynatable could infer from the returned results is (3) from above, i.e. how many records are in the filtered/queried set on the current page. So, it needs the returned JSON from the server to tell it (1), which is the totalRecordCount
, and (2), which is the queryRecordCount
.
Of course, if you don't want all of that, you can just turn off pagination and the record-count text, and tell dynatable that the results will be located at the root of the JSON returned by the server:
$('#remote').dynatable({
features: {
paginate: false,
recordCount: false
},
dataset: {
ajax: true,
ajaxOnLoad: true,
ajaxUrl: '//www.dynatable.com/dynatable-ajax.json',
records: []
},
params: {
records: '_root'
}
});