Get TR data from selected rows
Get TR data from selected rows
Hi guys,
I have a table with multi-select.
I need to loop through the selected rows and get the TR element as it has data attributes I need to get to. For example:
<tr class="job-list-row odd" data-jobnumber="job1" data-job_id="1" data-comp_num="900" role="row">
</tr>
var rowsSelected = jobTable.rows( { selected: true } ).count();
This gives me the correct number of selected rows. But if I try to iterate those using:
jobTable.rows( { selected: true } ).each(function(index){
console.log('row');
});
This only ever seems to execute once - I only get "row" once in the console.
I'm also not finding the proper syntax to access the elements in the node() If I use something like this inside the .each()
var tr = jobTable.row(index).node();
var trstr = JSON.stringify(tr);
console.log('Row: ' + trstr);
I see that it contains the data elements on the TR, but again, I only ever get ONE row, even if multiple rows are selected.
I'm sure the solution is staring me squarely in the face but I just cannot see it!
Essentially I need to loop through the selected rows and get the TR (node) and also some of the column elements (data) . What is the best way to do this?
Best regards,
This question has an accepted answers - jump to answer
Answers
Hi guys,
Something got seriously messed up with this message I just sent - something went wrong with the first code block and the rest got all messed up. Lets try again:
I need to loop through the selected rows and get the TR element as it has data attributes I need to get to. For example:
If I use:
This gives me the correct number of selected rows. But if I try to iterate those using:
This only ever seems to execute once - I only get "row" once in the console.
I'm also not finding the proper syntax to access the elements in the node() If I use something like this inside the .each()
I see that it contains the data elements on the TR, but again, I only ever get ONE row, even if multiple rows are selected.
I'm sure the solution is staring me squarely in the face but I just cannot see it!
Essentially I need to loop through the selected rows and get the TR (node) and also some of the column elements (data) . What is the best way to do this?
Best regards,
Try using
table.rows().every()
. For example:http://live.datatables.net/kakesejo/1/edit
Kevin
Hi,
THANK YOU! I knew this was staring me in the face! Will try it and let you know!
Best regards,
Hi,
This worked perfectly for what I needed! Thank you again!
.Best regards,