disable filtering of one or multiple columns (select inputs)
disable filtering of one or multiple columns (select inputs)
puseidr
Posts: 5Questions: 2Answers: 1
Hello, i want to use the Individual column searching (select inputs) Feature for datatables.
But i want to disable the filtering-option for one or more columns (some columns have to much information so the select input get a massive width and breaks the design).
what do i need to change in the js to disable the name-column and the start-date column from the examle (link above)
$(document).ready(function() {
$('#example').DataTable( {
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>' )
} );
} );
}
} );
} );
This discussion has been closed.
Answers
Got it!
i changed the js from
to:
and added the class "select-filter" to the table-header
now only the columns with the class will be filtered
Hi,
When I use,
I can see only one dropbox not every columns have a dropbox ???
and than I changed the codes like yours for two columns but again I can see one :( Is there any problem in my codes?
this is for my first codes
this one is second..I 've added
'.select-filter'
And Also Can I change the dropbox position ??? for example I want to locate top not bottom side...
Hi, I solved my problem... but now I have another one... If you notice that, I've added extra
<span ...></span>
but this tag effected the columns which have
class="select-filter"
these are the previews
https://yadi.sk/i/aM3biY9Ujy4L7
Although I have two "Personel Eğitimi" records, js codes not filter as in the image
https://yadi.sk/i/ju3eR9aRjy4f5
How can I edit js codes to solve this issue???
don't worry just put this line:
this.api().columns([1,2,3,5]).every( function ()......