load array of json
load array of json
denizdiana
Posts: 15Questions: 8Answers: 0
Hello everyone,
I have a json variable :
var data= {
"events": [
{
"name": "Jack",
"date": "05-03-2020",
"time": "18:10:11",
"action": "enter"
},
{
"name": "Jane",
"date": "05-03-2020",
"time": "08:40:11",
"action": "enter"
}
]
}
And I want to load this into datatable.
var dtable = $('#table').DataTable(
{
data : data,
columns: [
{ title: 'events.name' },
{ title: 'events.action' },
{ title: 'events.date' }
]
});
But it doesn't work. I can see the table but it is empty. What is the problem? Thank you so much.
This question has accepted answers - jump to:
This discussion has been closed.
Answers
Try changing line 4 to
data : data.events,
. It should be able to find the row data then.You will want to use
columns.data
to define your object based data source.column.title
will set the header titles. Maybe something like this:Kevin
I change it but it doesnt work it gives me
"DataTables warning: table id=Person - Requested unknown parameter '0' for row 0, column 0. For more information about this error, please see http://datatables.net/tn/4" error.
Sorry, you were too quick to see me edited response
Re-read my response.
Kevin