Snippets Collections
//in controller datatable
->addColumn('mass_delete', function ($row) {
  $selected = '';

  return  '<input type="checkbox" class="row-select test" value="'.$row->id.'">' ;
})


//in view table
 <th>_<input type="checkbox" value="1" id="select-all-row" data-table-id="incoming-messages-table"></th>

//in view datatable (to disable orderable on first column)
'columnDefs': [ {
  'targets': [0], /* column index */
  'orderable': false, /* true or false */
}]

//in view (action button and)
<button type="submit" class="btn btn-xs btn-primary" id="delete-selected">{{__('admin.delete selected')}}</button>
<form action="{{route('admin.incoming-messages.deleteArray')}}" method="post" id="delete_form">
  @csrf
<div class="inputs">

  </div>
</form>


//in view js
<script>
  $(document).on('click', '#select-all-row', function(e) {
    var table_id = $(this).data('table-id');
    if (this.checked) {
      $('#' + table_id)
        .find('tbody')
        .find('input.row-select')
        .each(function() {
        if (!this.checked) {
          $(this)
            .prop('checked', true)
            .change();
        }
      });
    } else {
      $('#' + table_id)
        .find('tbody')
        .find('input.row-select')
        .each(function() {
        if (this.checked) {
          $(this)
            .prop('checked', false)
            .change();
        }
      });
    }
  });


$(document).on('click', '#delete-selected', function(e){
  e.preventDefault();

  $ids = '';
  $html = '';
  $("input:checkbox:checked").each(function(){
    $ids += $(this).val() + ',';
    $html += '<input type="hidden" id="message_deleted" name="message[]" value="'+$(this).val()+'">';
  })
  $('.inputs').html($html);
  $('form#delete_form').submit() 
})
</script>

javascript:[].forEach.call(document.querySelectorAll('input[type="checkbox"]'),function(el){el.checked=true});
star

Fri Jan 19 2024 15:14:52 GMT+0000 (Coordinated Universal Time)

#php #laravel #selectall
star

Tue Oct 04 2022 13:27:23 GMT+0000 (Coordinated Universal Time) https://stackoverflow.com/questions/10908212/select-all-checkbox-by-javascript-or-console

#selectall

Save snippets that work with our extensions

Available in the Chrome Web Store Get Firefox Add-on Get VS Code extension