fnAddData Error - Requested unknown parameter '0' from the data source for row 0

fnAddData Error - Requested unknown parameter '0' from the data source for row 0

NightStarNightStar Posts: 2Questions: 0Answers: 0
edited March 2012 in DataTables 1.9
Hi,

I'm trying to display a AJAX XML response in Datatables. I'm able to get table initialized. But the data is not being shown on the datable. I get warning [quote] DataTables warning (table id = 'notes'): Requested unknown parameter '0' from the data source for row 0 [/quote].

Here's the script I am trying to use.
[code]


$(document).ready(function() {
var thisTable;
thisTable = $('#notes').dataTable({
"sPaginationType" : "full_numbers",
"bJQueryUI" : true
});
$("#searchform").submit(function() {
$.ajax({
url : '../MyProject/data.xml',
type : "GET",
success : addToTable
});
return false;
});

function addToTable(response) {
var $processNotes = $(response).find("processNote");

$processNotes.each(function(index, processNote) {
var $processNote = $(processNote),
addData = [];

addData.push($processNote.attr("id"));
addData.push($processNote.children("name").text());
addData.push($processNote.children("text").text());
addData.push($processNote.children("status").text());

thisTable.fnAddData(thisTable,addData);
});
}

});


[/code]

Can some point the error in this code that is causing the data not to be displayed? I have same number of headers in HTML table as in Script. I could also see the parsed XML data assigned to addData array in Firebug.

Replies

  • allanallan Posts: 61,449Questions: 1Answers: 10,055 Site admin
    > thisTable.fnAddData(thisTable, addData);

    No need to pass 'thisTable' as the first parameter - just give it addData as per the docs: http://datatables.net/api#fnAddData :-).

    Also, you should pass false as the second parameter to stop a redraw every time you add a new row in the loop as that would be really slow. Just add a call to fnDraw after the loop.

    Allan
  • NightStarNightStar Posts: 2Questions: 0Answers: 0
    edited March 2012
    Thanks a lot Allan. I initially tried without passing thisTable as parameter.
    As I received oSettings as null, I tried passing thisTable.

    fnDraw and passing false, did the trick for me :-)

    Thanks much!

    Great work on Datatables!
This discussion has been closed.