How to get rows with checked checbox
How to get rows with checked checbox
auto_reports
Posts: 14Questions: 5Answers: 0
I have dynamically created data table with server data and a check box in each row. I want to get the rows that are checked which I am going to use to update database.
Here is what I tried -
var dtdata = $('#apptMissed_table').DataTable();
var checked_data = $( dtdata.$('input[type="checkbox"]').map(function () {
return $(this).prop("checked") ? $(this).closest('tr') : null;
} ) ).data.toArray();
But I am getting the below error
Uncaught TypeError: $(...).data(...).toArray is not a function
Please help!
This question has an accepted answers - jump to answer
Answers
it should be ... data().toArray()
I guess.
You have ... data.toArray()
Thanks for your response, I have data() in my code. I somehow missed to add it here. I am still getting the error.
We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.
Cheers,
Colin
Hi Colin, thanks. Here is the fiddle link : https://jsfiddle.net/1hkg0yjo/6/
The problem is your code to get the
checked_data
is not returning a Datatables API, its returning a jQuery object. Therow-selector
docs show all of the options available to select the rows. You can use the results of you map function to select the rows to get the array. Here is the updated test case:https://jsfiddle.net/frow8epc/
Kevin
Thanks a lot Kevin, this seems to be working.