samedi 10 septembre 2016

Check the state of multiple checkboxes in nested table row using JQuery before action

I have a table that contains a list of recipients for gifts. Each recipient can have 1 or more gifts listed for them. I do this using a nested set of rows (1 nested row in a table cell per gift) in a table cell.

Each gift has 4 statuses (shown through chekcboxes) of Selected, Checked In, Out for Delivery, Delivered.

I need to hide the main row for the recipient when all of the checkboxes for a specific status are checked.

So, if I want to see only the recipients where a gift is not yet checked in, I would want to still see any recipients where only 1 gift may still be unchecked for 'Checked In' status.

I have the following to hide and show the rows now:

if (state === true) {
        switch(colId) {
            case "selectedFilter":
                $('input:checkbox.isSelected:not(:checked)').closest('.trMainData').hide();
                break;
            case "selectedFilterUnchecked":
                $('input:checkbox.isSelected:checked').closest('.trMainData').hide();
                break;
            case "checkedInFilter":
                $('input:checkbox.isCheckedIn:not(:checked)').closest('.trMainData').hide();
                break;
            case "checkedInFilterUnchecked":
                $('input:checkbox.isCheckedIn:checked').closest('.trMainData').hide();
                break;
            case "outForDeliveryFilter":
                $('input:checkbox.isOutForDelivery:not(:checked)').closest('.trMainData').hide();
                break;
            case "outForDeliveryFilterUnchecked":
                $('input:checkbox.isOutForDelivery:checked').closest('.trMainData').hide();
                break;
        }
    } else if (state === false) {
        $('table tr.trMainData:hidden').show();
    }

Where the 'state' is the state of a checkbox filter being clicked by the user (true or false) and 'trMainData' is the class on the main row for the recipients.

The issue is that if I set only 1 gift out of 2 as Checked In, then the entire recipient row is hidden, including the gift that has not yet been checked in.

Any help and suggestions, as always are greatly appreciated.




Aucun commentaire:

Enregistrer un commentaire