Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable filtering on one column and keep it for other columns in a jQuery Datatable?

I am new to jQuery and I need to know if there's any way to disable filtering for one of the columns in my jQuery datatable? My datatable has 5 columns and I need to disable filtering for the last column.

like image 641
DhawalV Avatar asked Feb 14 '13 16:02

DhawalV


4 Answers

Also you can do it like this:

    $('#ProductsTable').dataTable({
        "lengthMenu": [[20, 50, -1], [20, 50, "All"]],
        "pageLength": 20,
        "columnDefs": [
          { "orderable": false, "targets": [-1, 1] },
          { "searchable": false, "targets": [-1, 1] }
        ]
    });
like image 174
César León Avatar answered Sep 19 '22 01:09

César León


Here's how to disable global search filtering on multiple columns using Datatable ColumnDef.

var datatable = $('#datatable').DataTable({
    "deferRender": true,

    "columnDefs": [ 
        { targets: 0, searchable: true },
        { targets: [1,2], searchable: true },
        { targets: '_all', searchable: false }
    ]
});

This will enable search on column 0, 1 & 2 index wise and disable on rest of them all. The rules apply from top to bottom taking priority.

like image 25
Abdul Rehman Avatar answered Sep 20 '22 01:09

Abdul Rehman


This also works. Just change the number 4 to your desired column number:

    var table = $('#mytable').DataTable(
        {
            initComplete: function () {
                this.api().columns().every(function () {
                    var column = this;
                    if (column[0][0] == 4) {
                        console.log(column);
                        $(column.footer()).html('');
                    }
                });
            },
        }
    );
like image 43
user1322977 Avatar answered Sep 19 '22 01:09

user1322977


Use the bSearchable flag. From the docs:

// Using aoColumnDefs
$(document).ready( function() {
  $('#example').dataTable( {
    "aoColumnDefs": [
      { "bSearchable": false, "aTargets": [ 0 ] }
    ] } );
} );


// Using aoColumns
$(document).ready( function() {
  $('#example').dataTable( {
    "aoColumns": [
      { "bSearchable": false },
      null,
      null,
      null,
      null
    ] } );
} );
like image 20
Blazemonger Avatar answered Sep 20 '22 01:09

Blazemonger