Store and use JSON
Store and use JSON
I need to store a result from a $.getJSON and use it later on dataTables, heres my not-working code:
[code]
$.getJSON(
"index.php?getJsonData",
{
args:[ $('#id').val()]
},
function(data) {
dataGrid = data;
});
[/code]
So I stored the json return into dataGrid, then i try to do this:
[code]
$('#dGrid').dataTable().fnClearTable();
$('#dGrid').dataTable().fnAddData(dataGrid);
[/code]
And the superb 'undefined column size' message just appears :D
Does anyone know how to use a previously variable with json data to populate the dataTable?
[code]
$.getJSON(
"index.php?getJsonData",
{
args:[ $('#id').val()]
},
function(data) {
dataGrid = data;
});
[/code]
So I stored the json return into dataGrid, then i try to do this:
[code]
$('#dGrid').dataTable().fnClearTable();
$('#dGrid').dataTable().fnAddData(dataGrid);
[/code]
And the superb 'undefined column size' message just appears :D
Does anyone know how to use a previously variable with json data to populate the dataTable?
This discussion has been closed.
Replies
[code]
$('#dGrid').dataTable({
"bDestroy": true,
"aaData": dataGrid
})
[/code]
I'm not sure if your dataGrid has to be strictly an array of arrays of rows as it is in the example (http://www.datatables.net/release-datatables/examples/data_sources/js_array.html), though. I'm hoping that since DataTables allows array of objects in Ajax-sourced and server-side modes that maybe aaData does too.