Check All Checkbox

Check All Checkbox

donblaylockdonblaylock Posts: 10Questions: 4Answers: 0

I am trying to get code working to enable the user to check a filtered result in the DataTable by checking the checkbox at the top of the table in the header. This code works the first time I load the page but fails on subsequent calls. I have stepped thru the code and the logic is working and it is executing the correct code based on checking or unchecking the top check box - just failing after the first time I uncheck them.

This is my table:

        <table class="table responsive-table" id="UPSInvoices" width="100%" >

            <thead>
                <tr>
                    <th scope="col" width="5" align="center">
                        <input type="checkbox" id="chkPay" name="chkPay" >
                    </th>
                    <th scope="col" width="0" >ID</th>
                    <th scope="col" width="50" align="center">Item ID</th> 
                    <th scope="col" width="40" align="right">Balance</th>
                    <th scope="col" width="40" align="right">Invoice Age</th>
                    <th scope="col" width="40" align="center">Partial Paid</th>
                    <th scope="col" width="40" align="right">Posted Date</th>
                </tr>
            </thead>

            <tfoot>

And here is the code:

            $('#chkPay').click( function() {

                var isChecked = $('input[id="chkPay"]:checked').length > 0; 

                if (isChecked)
                {
                    $('input', table.fnGetNodes()).attr('checked',true); 
                }
                else
                {
                    $('input', table.fnGetNodes()).attr('checked',false);
                }

            });
This discussion has been closed.