Get data of all rows and extract input values and .data() attribute for every row
Get data of all rows and extract input values and .data() attribute for every row
Hi,
I am new to DataTables and trying to see if i can get it implemented into my site.
I've tried searching the DataTables forums and Googeling, but haven't found anything yet that answers my question. Probably i've read over it somewhere, but i am hoping someone will help me here.
Case
- a large number or table rows with 10 inputs on every table row (tr)
- what i need: to get all the input values for every row (visible or not) WITH the tr.data() and/or td.data() that might be set for that row.
Right now i am using this: $('#example').DataTable().rows().data().toArray() and getting this for every row:
["<input type=\"text\" value=\"0\">", "<input type=\"text\" value=\"0\">", "<input type=\"text\" value=\"0\">", "<input type=\"text\" value=\"0\">", "<input type=\"text\" value=\"0\">"]
a) i don't see the data() attribute that was attached to that row, how to get it?
b) how can i get the value of for instance row 0, third input? In Jquery i would use $('tr').first().find('input').val() but how can i do something like that with DataTables? So for all rows, not only the visible ones.
Not every row is in the DOM, so there must an object or something holding all table rows from where i can extract the value for every input on every table row and also get their data() attribute.
Any help would very much be appreciated. Apologies if this post is a bit large....
This question has an accepted answers - jump to answer
Answers
You can use
row().node()
to get thetr
orcell().node()
to get thetd
. There are plural forms of both APIs. If it makes sense for your solution you can iterate all the rows withrows().every()
or cells withcells().every()
.If this doesn't help then please provide a test case showing an example of what you have so we can help with your code.
https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case
Kevin