docs/

Load a JSON-file using AJAX

NOTE DataGridXL requires a commercial license.
json
[{
  "breed": "Kooikerhondje",
  "votes": 210,
  "origin": "The Netherlands"
}, {
  "breed": "Beagle",
  "votes": 235,
  "origin": "Great Britain"
}, {
  "breed": "Dalmatian",
  "votes": 90,
  "origin": "Croatia"
}]

Loading JSON using Vanilla JavaScript

To have DataGridXL display your remote JSON data, use JavaScript fetch method.

js
async function loadDataAndDisplayGrid() {
  // load data  
  const response = await fetch('/myapi/mydata.json');
  const data = await response.json();
  // display grid
  const grid = new DataGridXL("grid", {
    data: data
  });
}
loadDataAndDisplayGrid();

The above example assumes that mydata.json outputs valid JSON, where the data that's meant for the data grid is the root of the JSON-output.

Load JSON using jQuery

If you're including jQuery, you can use $.getJSON instead of fetch:

js
$.getJSON("/myapi/mydata.json", function(data){
  new DataGridXL("grid", {
    data: data
  });
});

Validating JSON

JSON looks very similar to JavaScript, but has stricter rules. If you're not sure if your server-side script outputs valid JSON, paste your file's output to jsonlint.com to check.