0

I want to provide a dropdown list to my DataTable on first row by following this page: jQuery DataTable. However, I don't want this row being sortable which the whole row will stay on the top of the tbody.

So how to set this row will not be sortable?

$('.tables').dataTable({
  "columnDefs": [{
    "targets": 4,
    "orderable": false
  }],
  "order": [
    [9, "desc"]
  ],
  'initComplete': function() {
    this.api().columns().every(function() {
      var column = this;
      console.log(column);
      var header = column.header();
      if (header.innerText != "myKeyword") {
        console.log(column.header());
        var select = $('<select>' +
            '<option value="All">All</option>' +
            '</select>')
          .appendTo($(column.header()))
          .on('change', function() {
            var val = $.fn.dataTable.util.escapeRegex(
              $(this).val()

            );

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

        column.data().unique().sort().each(function(d, j) {

          select.append('<option value="' + d + '">' + d + '</option>')
        });

      }

    });
  }
});
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
MRWonderFuXker
  • 203
  • 3
  • 19

0 Answers0