Datatables fnGetData returns two rows for two checkboxes in a row? in fact it is only one row, rte?

Datatables fnGetData returns two rows for two checkboxes in a row? in fact it is only one row, rte?

tinmichaeltinmichael Posts: 4Questions: 0Answers: 0
edited May 2012 in General
$('input:checked ', bookingDetailsDataTable.fnGetNodes()).each(function (index) {
var row = $(this).closest('tr');

alert(index);});

For the above code, I have got the alert twice, first zero and second two. even though I check only one row, but two checkboes. When I check the first checkbox, I have got the correct value. But checking the second checkbox in the same rote, it returns two index value, I think fnGetData thinks that even though there is only one row, since there is two checkboxes in a row, it regards as two rows. Please let me know if there is any extra filter that I need to put when getting the fnGetNodes? I have tried like $('input:checked [name$="cbSomething"] ', bookingDetailsDataTable.fnGetNodes()).each(function (index); }); but not successfult. Your help is much appreciated. Datatables Rocks!!!

Replies

  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin
    I don't quite understand I'm afraid - you've checked two check boxes, and your selector specifically says to get all checked input boxes in the table rows (i.e. two), but you expect only one?

    fnGetNodes just gets an array of TR elements, and the jQuery selector runs over that. Perhaps it makes more sense using the newer API:

    [code]
    bookingDetailsDataTable.$('input:checked').each( function () { ... } );
    [/code]

    that will still get all checked input boxes, but it should be more obvious what is happening. Sounds to me like you need to make your selector, more selective.

    Allan
This discussion has been closed.