Reload table with new data

Reload table with new data

BCKurtBCKurt Posts: 5Questions: 0Answers: 0
edited June 2011 in DataTables 1.8
I load a table with some JSON returned from a .php file:

[code]
nvTable = $('#NV').dataTable( {
"bJQueryUI": true,
"sDom": 'T<"clear">lfrtip',
"bAutoWidth": false,
"aoColumns": [
{"sWidth": "15%"},
{"sWidth": "10%", "sType": "numeric"},
{"sWidth": "15%", "sType": "numeric"},
{"sWidth": "60%"},
],
"iDisplayLength": 25,
"bProcessing": true,
"sAjaxSource": "makeTable.php?type=NV"
} );
[/code]

I have a combobox that allows the user to specify a model to display. I want to pass that along to makeTable.php to create a different table with some different data:

[code]
$("#NVBox").change(function() {
var model = $("#NVBox option:selected").text();
$.ajax({
type: "GET",
url: "makeTable.php",
data: ({type: "NV", model: model}),
cache: false,
dataType: "json",
success: function(json) {
nvTable.fnClearTable(0);
nvTable.fnAddData(json);
}
});
});
[/code]

However, this gives me the following error:

DataTables warning (table id = 'NV'): Requested unknown parameter '0' from the data source for row 0

My makeTable.php file checks to see if model is set, if not, then it returns everything. If it finds the model, then it only returns those along with the price for the model (left out in the main table).

Any ideas?

Replies

  • allanallan Posts: 63,368Questions: 1Answers: 10,449 Site admin
    edited June 2011
    What does the JSON look like? Is it just a 2D array? My guess is you need to give fnAddData 'json.aaData'.

    Allan
  • BCKurtBCKurt Posts: 5Questions: 0Answers: 0
    I was able to fix it with:

    nvTable.fnReloadAjax('generateTableData.php?type=NV');

    And having the fnReloadAjax JS code above the table initialization.

    Thanks.
This discussion has been closed.