Datatable Custom Toolbar Not Working With Select2 CSS

This is the code

<link href="" rel="stylesheet">
<script src=""></script>  
<script src=""></script>
<script src=""></script>
<script src=""></script>
<script src=""></script>
<script src=""></script>
 <!-- problem lays here -->
    <link href="" rel="stylesheet" />

<script type="text/javascript">

$(function () {
      headers: {
          'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')

var table = $('.data-table').DataTable({
    processing: true,
    serverSide: true,
    responsive: true,
    ajax: "{{ route('users.index') }}",
    dom: '<l<"toolbar">f>rtip',
    initComplete: function(){
      $("div.toolbar").html('<div style="float:left;margin-left:4px;"><select class="form-control select2bs4 select2-hidden-accessible trash_all" style="width:140px;height:32px;margin-left:10px;" data-select2-id="17" tabindex="-1" aria-hidden="true"><option selected="selected" data-select2-id="19">Bulk Actions</option><option data-select2-id="38" value="trashAll">Trash</option></select></div><div style="float:left;margin-left:20px;"><select onchange="window.location = this.options[this.selectedIndex].value" class="form-control select2bs4 select2-hidden-accessible download-doc" style="width:140px;height:32px;margin-left:10px;padding-bottom:5px"" data-select2-id="17" tabindex="-1" aria-hidden="true"><option selected="selected" data-select2-id="19" value="{{route('users.index')}}">Download</option><option data-select2-id="38" value="{{route('users.pdf')}}">PDF</option><option data-select2-id="39" value="{{route('users.excel')}}">XLS</option><option data-select2-id="39" value="{{route('users.word')}}">Doc</option></select></div>');
    columns: [
        {data: 'DT_RowIndex', name: 'DT_RowIndex'},
        {data: 'name', name: 'name'},
        {data: 'email', name: 'email'},
        {data: 'roles', name: 'roles'},
        {data: 'status', name: 'status'},
        {data: 'action', name: 'action', orderable: false, searchable: false},

$("div.toolbar").css("float", "left");

  ajax: {
  url: '{{ url('searchrole') }}',
  processResults: function(data){
  return {
    results:{return {id:, text:} })

When I remove this code

<link href="" rel="stylesheet" />

Custom toolbar is working
Datatable Custom Toolbar Not Working With Select2 CSS

But, when I let the code above exist, custom toolbar element is gone. I should make it exist because select2 not working if I remove code above.


Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

You can display those select controls by doing this:

(1) Un-comment your select2.min.css resource again.

(2) Remove this class from your code: select2-hidden-accessible. It appears in 2 places in your initComplete function and is causing your controls to be hidden.

(There may be other tweaks you need to make, depending on how the remaining classes in that block of HTML code interact with the select2 CSS.)

All methods was sourced from or, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Notify of

Inline Feedbacks
View all comments
Would love your thoughts, please comment.x