Could not add rows with json array
Could not add rows with json array
I couldn't add rows with the json array format
Even I tried with the example it's still no luck.
This is from example (https://datatables.net/reference/api/rows.add())
**//Initialize new table
var table = $('#example').DataTable();
table.rows.add( [ {
"name": "Tiger Nixon",
"position": "System Architect",
"salary": "$3,120",
"start_date": "2011/04/25",
"office": "Edinburgh",
"extn": "5421"
}, {
"name": "Garrett Winters",
"position": "Director",
"salary": "$5,300",
"start_date": "2011/07/25",
"office": "Edinburgh",
"extn": "8422"
} ] )
.draw();**
When I run the example, there is an error message :
"DataTables warning: table id=reportTable - Requested unknown parameter '0' for row 0, column 0. For more information about this error, please see http://datatables.net/tn/4"
The error message is also attached
Anyone please helpp
Answers
what you are showing us is not an array format. it is an array of objects. It looks you are trying to mix an array of arrays with an array of objects.
https://datatables.net/examples/basic_init/zero_configuration.html is an example of an array of array.
https://datatables.net/examples/ajax/objects.html this is an example of array of objects.
the two cannot be mixed.
Thanks for your suggestion. But I'm still wonder why I couldn't generate the table with the code brought from the example. What have I done wrong?
This document explains the differences in data structures:
https://datatables.net/manual/data/
Like Bindrid said.... Basically you aren't defining the columns with
columns
so Datatables expect any array of data elements not an array of objects.Kevin