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.
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] }
]
});
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.
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('');
}
});
},
}
);
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
] } );
} );
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With