Count selected row

Count selected row

LArmstrong85LArmstrong85 Posts: 21Questions: 14Answers: 0

Hi,
I have a datatable to which I added a column with a checkbox. I would be able to
count the number of checkbox selected and save in an array a list of this rows, but
I have a problem with the checkbox click event in Jquery.
Can you help me?
This is a little example that differ with mine only in the fact that in my project I use Ajax source data.
(I don't know how i can do it in live.datatable.net).

http://live.datatables.net/qisogeje/7/edit

Thank you in advance!

Answers

  • allanallan Posts: 63,687Questions: 1Answers: 10,500 Site admin

    $("input[type=checkbox]").on("click" , refreshSelectedItem());

    You are executing your function there. So what jQuery sees is really:

    $("input[type=checkbox]").on("click" , undefined);
    

    since your function isn't returning anything.

    I think what you want is:

    $("input[type=checkbox]").on("click" , refreshSelectedItem);
    

    You should also use $() to query all rows in the table, not just those on the current page.

    Allan

  • LArmstrong85LArmstrong85 Posts: 21Questions: 14Answers: 0

    Thank you Allan.
    I tried your suggestion but it doesn't work, Can you give me an example please?

  • LArmstrong85LArmstrong85 Posts: 21Questions: 14Answers: 0

    Hi Allan,
    i retrieve a solution for count the number of row selected.
    This is the example even if it doesn't work in live.datatable (in my pc it works!)
    http://live.datatables.net/qisogeje/9/edit

    I also need to collect all checked row and send to server in JSON format.
    How I can do it?

    Thank you very much!

  • allanallan Posts: 63,687Questions: 1Answers: 10,500 Site admin

    You could use the same approach as in this example.

    Allan

  • LArmstrong85LArmstrong85 Posts: 21Questions: 14Answers: 0

    Ok,
    this is the same solution that I had in my mind. On click on combobox I would to add a class selected on table rows for retrieve them like the example. But how I can retrieve the corresponding row that I have selected in my click handler?

  • allanallan Posts: 63,687Questions: 1Answers: 10,500 Site admin

    Assuming your event handler is targeting a descendent of the row you would just use a little bit of jQuery: $(this).closest('tr').

    Allan

This discussion has been closed.