How do you load jquery data table state using a json file? The API does not seem to provide a load method.
Thanks in advance.
The library link is https://datatables.net/
How do you load jquery data table state using a json file? The API does not seem to provide a load method.
Thanks in advance.
The library link is https://datatables.net/
It sounds like you don't want to use the Ajax source for data, which means that you can use the Javascript array option for loading data. You'll have to write your own code to parse the JSON file into a Javascript array, but then you can simply load it to the DataTable with the following code block (stolen blatantly from this stackoverflow post by @jessegavin and updated very slightly to 1.10.x standards by me):
var json = {
BrowserStats : [
{ engine: "Trident", browser: "IE 4.0", platform: "Win 95+", version: 4 },
{ engine: "Trident", browser: "IE 5.0", platform: "Win 95+", version: 5 },
{ engine: "Trident", browser: "IE 5.5", platform: "Win 95+", version: 5.5 }
]
};
$('#example').dataTable( {
data: json.BrowserStats,
columns: [
{ data: "Engine" },
{ data: "Browser" },
{ data: "Platform" },
{ data: "Version"}
]
});
In fact, I would strongly recommend just checking out that post linked above, as Jesse provides a really great summary of data loading sources for DataTables.
Check it out here
Credit again to @jessegavin