Friday, May 10, 2024
 Popular · Latest · Hot · Upcoming
100
rated 0 times [  101] [ 1]  / answers: 1 / hits: 8318  / 7 Years ago, tue, august 8, 2017, 12:00:00

I've got datatables set up nicely and with the select extension - I have this code for when someone uses a report and it loads another page using some cell content from the table to pass to the report. That works fine, however - I need to be able to pass a data-element of each <tr> of the table instead of the row data...



This is my current code:



var table = $('#table_search_project').DataTable();

//then re-run the code to get the selected rows
var id_list = $.map(table.rows('.selected').data(), function (item) {
return item[1]
});


So you can see, I used to use item[1] to return, but I really want to be able to get the <tr> object so I can retrieve the data-something-id property (but I don't want to show it - hence the issue)


More From » jquery

 Answers
1

I worked it out. Too hasty to ask in SO!



I used this instead:



var id_list = $.map(table.rows('.selected').nodes(), function (item) {
return $(item).data(entity-id);
});


The nodes() collection sends me back the <tr> elements instead of the data. Exactly what I wanted. Found the information here:



https://datatables.net/reference/api/row().node()


[#18801] Sunday, August 6, 2017, 7 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
felixa

Total Points: 180
Total Questions: 113
Total Answers: 108

Location: Palau
Member since Sat, Aug 21, 2021
3 Years ago
;