DataTables warning: Requested unknown parameter 'id' for row 3, column 0
DataTables warning: Requested unknown parameter 'id' for row 3, column 0
I am trying to implement add row when the user clicks on add row button.
I tried to follow this example: https://datatables.net/examples/api/add_row.html
But it gives me error as:
DataTables warning: table id=example - Requested unknown parameter 'id' for row 4, column 0. For more information about this error, please see http://datatables.net/tn/4
When I press OK to the error it adds row but no data is added.
I have created my sample at this fiddle:
https://jsfiddle.net/aman1981/x7jstfw1/26/
Thanks for looking into.
This question has accepted answers - jump to:
Answers
Since you are using
column.data
you are telling Datatables to use objects. You need to change this:Which is adding an array to be an object, like this:
Kevin
Thanks for the reply.
This gives me error :
"Expected an assignment or function call" and Uncaught SyntaxError: Unexpected token :
on the line
id: "2"
Never mind I got it.
I needed to pass as an object rather than array
table.row.add({
"id": counter +'.1',
"name": counter +'.2'
}).draw(false);
Good spot
Sorry colin not related to this, but I am using knockout to render my grid. I want to get rid of the subscribe method and just bind to the grid. As by using the subscribe it refreshes and the new added row is lost since its on client side currently. Whats the simplest code that I have to use to bind back to my array/json. The data would be from ajax call to my controller.
You have my jsfiddle as:
https://jsfiddle.net/aman1981/x7jstfw1/26/
Let me know if I need to open a new post for this.
Thanks
If you want to use Knockout observables inside DataTables, there are a few posts on that topic that you could refer to.
There isn't anything in DataTables core that is specific to Knockout though.
If you want to remove that extra complexity and bypass Knockout, the Ajax section of the manual is where to start.
Allan
Thanks allan I will look through.
Hi ama1981,
Take a look at this fiddle - the initial table is loaded now in the
initComplete
, meaning that the subscribe can be entirely removed.https://jsfiddle.net/koj64ozu/14/
Cheers,
Colin