Data after DOM update
Data after DOM update
El_Matella
Posts: 12Questions: 6Answers: 0
Hi, I am trying to manipulate data with datatables but I am having a problem with the update of the data.
Let's imagine I have a simple table:
<table>
<thead>
<th>My Title</th>
</thead>
<tbody>
<tr>
<td class="data">My Data</td>
</tr>
</tbody>
</table>
With Javascript I am changing the DOM (with x-editable), and the td content is changing. But the, when I try to take the data, the old data is returning:
$('table tbody').on( 'click', '.data', function () {
var isSelected = false;
var data = table.row( $(this).parents('tr') ).data();
console.log(data);
});
And I would like to know how to fix that :)
Tell me if my question is not good, I will try to ask it in a better way.
Thanks a lot for your answers and have a nice day!
This discussion has been closed.
Answers
I use x-editable too actually.. you have to change the dom, then invalidate the row.
And ill tell you after i spent a long long time using the dom as the source for my DT, which uses xeditable... its 100x easier using AJAX as the source, then drawing up the links in the createdRow.
I can show you all my code if ya want, it now uses ajax, but i can find the dom version in my revision history
Hi, I am actually using Ajax as data source for the table, I used the DOM for the example in this post..
I am going to look at your code, thanks a lot for sharing!
I will maybe have some questions after that :)
Np bud. Post the questions in threads tho, ill answer accordingly. You can pm me when you make new threads tho
I use the AJAX source and update the table after any updates via the
ajax.reload()
function.@allan, is it possible to reload the data that DataTables has, without reloading the entire table? Then just update the one row thats different?
Im not sure if its possible to update the data source without reloading the entire table
Yes, but that isn't really a built in function since it is a function of whatever setup you have. At the moment you'd need to use
row.data()
to tell DataTables: 1. which row to update, and 2. what data to update it work.Allan
Hi, this is exactly what I did, here is the final code, if it can help someone in the future:
And the most important part is in the createdRow callback:
As you can see, I am using the
row.data()
to update value :)Your closing span tag on line 5 is broken, fyi
@EL_Matella the issue i had was i wanted to update more than just THAT item in the row, i had columns for "modified" and "modifier", so what i did (before uaing ajax on the table) was have the response body from the x-editable source be the new row content, then update the row with that
Might be useful to you