简体   繁体   中英

bootstrap datatable sorting not working properly

I am using bootstrap datatable , when I click on sorting icon on second column then only it removes icon from first column, otherwise it appears on page load, I have written column number to remove from ordering in code but not working.

   $('#example').DataTable( {

  "columnDefs": [ {
    "targets": [0,1],
    "orderable": false
  },

  { "width": "8%", "targets": 0 },
  { "width": "13%", "targets": 1 } ],


  initComplete: function () {

    this.api().columns().every( function () {
      var column = this;
      var select = $('<select><option value=""></option></select>')
      .appendTo( $(column.footer()).empty() )
      .on( 'change', function () {
        var val = $.fn.dataTable.util.escapeRegex(
         $(this).val()
         );

        column
        .search( val ? '^'+val+'$' : '', true, false )
        .draw();
      } );

      column.data().unique().sort().each( function ( d, j ) {
        select.append( '<option value="'+d+'">'+d+'</option>' )
      } );
    } );
  }
});

Datatables uses the first column as ordering by default, and thus renders the icon that states which column is the one providing the ordering. If you want to remove it then you have to provide an explicit ordering in your configuration, such as:
order: [[1, 'asc']],
which will use the second column as default ordering.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM