datable rows().every and this.nodes() incompatibility with datatable 2?

datable rows().every and this.nodes() incompatibility with datatable 2?

miguelaguilarmiguelaguilar Posts: 2Questions: 0Answers: 0
edited June 2024 in Free community support

Link to test case:
This works with datatable 1.13.X -> https://live.datatables.net/mexezomi/2/edit
The same code but running on datatable 2.0.X, doesn't work -> https://live.datatables.net/waqunabe/2/edit

Error messages shown:
"TypeError: this.nodes is not a function ...

Description of problem:
I have this table that rows can be added dynamically and every row have input for the user put some values, and finally I get this data with the datatable API functions as rows.every(), then I get the inputs with this.nodes().to$().find("input").
When I upgrade datatables to version 2 this stoped working getting an error.
Do you have any suggestion to improve this code and make it compatible with datatable 2?
Thank You!!


var table = new DataTable("#example",{ paging:false, columns: [ { "data":null, "title": "A", render: function(data, type, full, meta){ return "<input type='text' value='ValueA' name='A' id='id_a'>"; } }, { "data":null, "title": "B", render: function(data, type, full, meta){ return "<input type='text' value='ValueB' name='B' id='id_b'>"; } }, { "data":null, "title": "C", render: function(data, type, full, meta){ return "<input type='text' value='ValueC' name='C' id='id_b'>"; } } , { "data":null, "title": "<button id='add_row'>add+</button>", "defaultContent" : "" } ], data: [{},{}] }); table.off("click").on("click", "#add_row", function(){ table.row.add({}); table.draw(); }); function saveValues(){ let arrValues = []; table.rows().every(function (rowIdx, tableLoop, rowLoop){ // this.nodes() doesnt work with datatables 2.x.x let cells = this.nodes().to$().find("input"); let data = '{'; for (const cell of cells){ data += `"${cell.name}" : "${cell.value}",`; } data = data.slice(0,-1); data += '}'; data = JSON.parse(data); arrValues.push(data); }); console.log(arrValues); }

Replies

Sign In or Register to comment.