Multiple dataSrc elements in one json file
Multiple dataSrc elements in one json file
Hi,
I have json file which will have several "top level" nodes like the following:
{"system1": [
{"element": "xxyy", "mode": "on", "type": "physical"},
{"element": "xxyy", "mode": "on", "type": "virtual"}],
"system2":[{"element": "xxyy", "mode": "on", "type": "physical"},
{"element": "xxyy", "mode": "on", "type": "virtual"}]
}
so the datatable ajax work just fine with the following:
$('#myTable').DataTable( {
"processing" : true,
"ajax": {
url: "system_list.json",
dataSrc: "system1"
"columns": [
{"data" : "element" },
{"data" : "mode" },
{"data" : "type" }
]
} );
But how I would get all systems in the same table ?
Help would be highly appreciated..
Answers
You have to flatten the array. DataTables requires that an array be passed into it for the data in the table, where each element in the array is a row. It cannot currently source from multiple arrays automatically (you could do it programmatically with
rows.add()
).You could use the
ajax.dataSrc
option as a function to flatten the array and then just return the flattened array from the function.Allan