Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Crazylife's avatar

How to select all checkbox from datatable by one click

<th>{{ Form::checkbox('select_all' ,'1',false,array('id' => 'select-all')) }}</th>
<td>{{ Form::checkbox('item[]', $id->id, false) }}</td>

<script>
var table = $('#table').DataTable({
            "responsive": true,
  });

$('#select-all').on('click', function(){

            var rows = table.rows({ 'search': 'applied' }).nodes();
            $('input[type="checkbox"]', rows).prop('checked', this.checked);
        });

        $('#table tbody').on('change', 'input[type="checkbox"]', function(){
      
            if(!this.checked){
                var el = $('#select-all').get(0);           
                if(el && el.checked && ('indeterminate' in el)){
                    el.indeterminate = true;
                }
            }
        });
</script>

I tried above method but not working, any solution to fix it?

0 likes
0 replies

Please or to participate in this conversation.