columns.searchable Filterrow on / off
columns.searchable Filterrow on / off
seotech
Posts: 8Questions: 4Answers: 0
Hello,
i use this snippet for realize individual column filtering as a second header row:
var table = $('#main').dataTable( {
...
initComplete: function () {
var r = $('.dataTables_scrollFootInner .dataTable tfoot tr');
r.find('th').each(function(){
$(this).css('padding', 8);
});
$('.dataTables_scrollHeadInner .dataTable thead').append(r);
$('#search_0').css('text-align', 'left');
}
} );
$('.dataTables_scrollFootInner .dataTable tfoot th').each( function () {
var title = $('.dataTables_scrollHeadInner .dataTable thead th').eq( $(this).index() ).text();
$(this).html( '<input type="text" style="width:100%;" placeholder="'+title+'" />' );
} );
// Apply the search
table.columns().eq( 0 ).each( function ( colIdx ) {
$( 'input', table.column( colIdx ).footer() ).on( 'keyup change', function () {
table
.column( colIdx )
.search( this.value )
.draw();
} );
} );
My problem is:
This snippet append a input for all columns, but i need a logic to "disable / hide / dont create" the input field where
columns.searchable
is false.
A second question is, are they any other cool filter plugins / extensions with more features like the MS Excel Autofilter or search operators like ">=, is null, is not null, <=, ..."
This discussion has been closed.
Answers
There isn't currently a public API to determine if a column is searchable - that is something I will address soon. In the mean time, you could add a class to the columns which are searchable (or not and just invert the logic) and then check for that class before adding the filtering.
You might want to take a look into YADCF.
Allan