Question

I'm trying generate a list after an obtained JSON, I found docs from dynatable library so they can populate a table in the ajax way receiving a JSON.

However, what if I already have the json stored in a variable. I've tried this so far:

var json = {
              "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
            }

var table = $('#resultados').dynatable({
    dataset: {
        ajax: true,
        ajaxUrl: json,
        ajaxOnLoad: true,
        records: []
    }
})

So I'm getting a 404 code, I understand that's because that's not an actual route. But what can I do to tell library to request for that file. Isn't even ajax required?

Was it helpful?

Solution

Since you already have it in a javascript array called json, you can (I make the assumption that you want to use json.records):

$('#resultados').dynatable({
  dataset: {
    records: json.records
  }
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top