TheNiceGuy
TheNiceGuy

Reputation: 3730

Add JSON data to datatable

I want to add JSON data to a existing datatable.

The JSON data looks like this:

[
    ["Trident","Internet Explorer 4.0","Win 95+","4","X","X"],
    ["Trident","Internet Explorer 4.0","Win 95+","4","X","X"],
    ["Trident","Internet Explorer 4.0","Win 95+","4","X","X"],
    ["Trident","Internet Explorer 4.0","Win 95+","4","X","X"]
]

I tried:

$('#' + tab + '_table').dataTable().fnAddData(data);

data is holding the JSON data.

Anything seems wrong there since it adds only one row with this:

enter image description here

Upvotes: 2

Views: 14142

Answers (1)

user1864610
user1864610

Reputation:

It looks like you're asking dataTables to add raw JSON data to your table. You should parse it first with JSON.parse() and add the resulting Javascript array.

var jsdata = JSON.parse(data);
$('#' + tab + '_table').dataTable().fnAddData(jsdata);

Upvotes: 6

Related Questions