row().data() undefined after destroy and re-init table
row().data() undefined after destroy and re-init table
Hello,
i've got a problem with a "table.row.data()" content in a table i build dynamically.
I've tried to made an example here: http://jsfiddle.net/ps4bvmq5/
First of all:
It's not possible to change the way the table are populated. So i've to keep this piece of code.
Problem:
Change list select to "list 1".
Drag and Drop one of the rows.
An alert will show you a table.row.data() content.
It's ok.
Now change the list in the select (list 2) and drag and drop one of the row again....
Now, table.row.data() in undefined.
That's the problem.
It seems like the first one table init it's going ok and the others ones no.
What i'm wrong?
Thanks in advance
PS: never mind about other errors it's about jsfiddle config.
This question has an accepted answers - jump to answer
Answers
Hi,
You need to remove the previously added
row-reorder
event listener since that is still present on the table (and the sametable
element is being reused).Here is an updated example: http://jsfiddle.net/ps4bvmq5/1/ .
Allan
Allan... you saved my day!
Thanks!
PS: for the future... how can i check if some events are still present on my table and if i properly destroy and re-init it?
You could use the
.DT
namespace. It isn't documented since its an internal action, but DataTables will automatically remove events with that namespace when destroying the table: http://jsfiddle.net/ps4bvmq5/2/ .The other option is to use your own event namespace and just call
off
for that whole namespace.Allan
I've got it!
Perfect!
Thanks again