4

I want to select all my checkbox

I have an input in header of datatables like this

  <th style="width: 25%" ><input type="checkbox" name="checkall" class="select-checkall" id="checkall" value=""></th>

i use it like this to checked it but only work in the page that iam

   $("#checkall").click(function(){
            $(':checkbox').prop('checked', true);                       
     });  

check this fiddle http://jsfiddle.net/juxHn/46/

3

1 Answer 1

5

jQuery will not be able to find checkboxes in other pages than the current one because DataTables somehow hides them (maybe removes them from DOM?)

Please refer to DataTables API to access your table cells irrespective of which ones are currently shown or not / of which page you are on.

In your case, you could do:

// Use "DataTable" with upper "D"
oTableStaticFlow = $('#flow-table').DataTable({
    "aoColumnDefs": [{
        'bSortable': false,
        'aTargets': [0]
    }],
});

$("#flowcheckall").click(function () {
    var cells = oTableStaticFlow.column(0).nodes(), // Cells from 1st column
        state = this.checked;

    for (var i = 0; i < cells.length; i += 1) {
        cells[i].querySelector("input[type='checkbox']").checked = state;
    }
});

Demo: http://jsfiddle.net/juxHn/47/

Sign up to request clarification or add additional context in comments.

3 Comments

I found one issue in the above fiddle.
@vimalkumar Feel free to comment your finding and/or provide your own solution / fixed fiddle.
Hooray! Well done saved me a lot of head scratching!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.