How to get rows with checked checbox

How to get rows with checked checbox

auto_reportsauto_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

  • rf1234rf1234 Posts: 2,991Questions: 87Answers: 421

    it should be ... data().toArray()
    I guess.
    You have ... data.toArray()

  • auto_reportsauto_reports Posts: 14Questions: 5Answers: 0

    Thanks for your response, I have data() in my code. I somehow missed to add it here. I am still getting the error.

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    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

  • auto_reportsauto_reports Posts: 14Questions: 5Answers: 0

    Hi Colin, thanks. Here is the fiddle link : https://jsfiddle.net/1hkg0yjo/6/

  • kthorngrenkthorngren Posts: 21,330Questions: 26Answers: 4,951
    Answer ✓

    The problem is your code to get the checked_data is not returning a Datatables API, its returning a jQuery object. The row-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

  • auto_reportsauto_reports Posts: 14Questions: 5Answers: 0

    Thanks a lot Kevin, this seems to be working.

Sign In or Register to comment.