How to Filter rows that have a checkbox ticked?

How to Filter rows that have a checkbox ticked?

cheeseslicecheeseslice Posts: 1Questions: 1Answers: 0

What I would like to do is filter all rows that have a checkbox ticked in the data table.

I have a custom button created but I seem to be having a problem being able to select the element to see if it is ticked or not.

Structure for a row looks like this:

<tr>
<td>Some Data</td>
<td>Some Data</td>
<td>Some Data</td>
<td>Some Data</td>
<td>Some Data</td>
<td>Some Data</td>
<td><span class="disabled"><input id="someId" name="somename" checked="checked"></span></td>
</tr>

This is the code I have running inside the function for my custom button:
$.fn.dataTable.ext.search.push(
function (settings, data, dataIndex) {
console.log($(table.row().node()));
return $(table.row(dataIndex).node('#MainContent_EnquiriesMainContent_StaffGridView_ctl01_0[type=checkbox]'));
}
);
table.draw();

This obviously isn't working but I just can't work out how to inspect the element.

I realise that it should be something like: $(table.row(dataIndex).node().attr( ) ) but I just can't work it out.

The console log shows all the rows being returned so I am half way there!!

Thanks in advance

Answers

  • kthorngrenkthorngren Posts: 20,342Questions: 26Answers: 4,776

    Maybe this will work in your function:

    $.fn.dataTable.ext.search.push( function (settings, data, dataIndex) {
            var found = false;
            var row = table.row(dataIndex).node();
            if (!$(row).find('input').prop('checked')) {
              found = true;
            }
            return found;
    });
    

    I think you will want to use .prop() instead of .attr().
    Kevin

This discussion has been closed.