columns.searchable Filterrow on / off

columns.searchable Filterrow on / off

seotechseotech Posts: 8Questions: 4Answers: 0
edited October 2014 in Free community support

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, <=, ..."

Answers

  • allanallan Posts: 61,890Questions: 1Answers: 10,143 Site admin

    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.

    are they any other cool filter plugins / extensions with more features

    You might want to take a look into YADCF.

    Allan

This discussion has been closed.