dimanche 4 septembre 2016

jquery to filter table with checkboxes by checkbox state using Materialize switches

I have a table filled and created dynamically, and in some of the columns I use the Materialize switches to set values in a database.

I want to use the Materialize checkbox on these columns to filter the table down to those switches that are in the "on" position. This is 'checked' in the html.

I have text fields on other columns and am filtering successfully with those, but I can't figure out how to reference a specific column on a row where the switch state is 'checked'.

<table>
    <tr>
        <td>
            <div class="switch">
                Selected<br />
                <label>
                Off
                <input type="checkbox" class="isSelected" checked="    ">
                <span class="lever"></span>
                On
                </label>
            </div>
        </td>
        <td>
            <div class="switch">
                Checked In<br />
                <label>
                Off
                <input type="checkbox" class="isCheckedIn" checked="    ">
                <span class="lever"></span>
                On
                </label>
            </div>
        </td>
     </tr>
</table>

This id done in Meteor, so the handlebar values basically give checked or false, in order to dynamically turn the switch to on based on the database value.

JQuery

'click .checkFilter' (event) {
    console.log('checked or unchecked');
    var colId = event.currentTarget.id;
    var state = event.currentTarget.checked;
    console.log('State of ' + colId + ' is now ' + state);
    $('table tr.trInner').each(function() {
        if ($('tr>td:nth-child(2)').checked) {
            console.log('Checked');
        }
    });

},

I'm just trying to console log something now if it can detect that an item in the column is checked, and I don't even get that.

Any help is greatly appreciated.




Aucun commentaire:

Enregistrer un commentaire