Error while trying to add a new row in a DataTable

Error while trying to add a new row in a DataTable

user1212user1212 Posts: 6Questions: 0Answers: 0
edited February 2014 in General
I have the dataSource defined as

[code]function getData(){
var arr = [];
for(var i=0; i<1000; i++){
var obj = {
'name': 'John', 'company' : 'ABC Corp', 'salary': '$x'
};
arr.push(obj);
}
return arr;
}[/code]

The table is being rendered as

[code]
var arr = getData();
$('#table1').dataTable({
'aaData': arr,
'aoColumns': [
{'sTitle': 'name'},
{'sTitle': 'company'},
{'sTitle': 'salary'}
]
})[/code]

Now when i try to add a new row to the dataTable as

[code]
$('#table1').dataTable.fnAddData([
" ", " ", " "
]);
[/code]

I get an error as

DataTables warning (table id = 'table1'): Requested unknown parameter 'name' from the data source for row 1001

What can be causing this?

Replies

  • allanallan Posts: 63,692Questions: 1Answers: 10,500 Site admin
    Your fnAddData is adding the data as an array - but you need to add it in the same format (i.e. an object with `name` , `company` , etc, properties) as your main data.

    Allan
This discussion has been closed.