columns().search() and bFilter

columns().search() and bFilter

MartyFMartyF Posts: 14Questions: 5Answers: 1

Hi all,

I am using the example code to filter each column separately :

// Setup - add a text input to each footer cell
$('#example tfoot th').each( function () {
    var title = $('#example thead th').eq( $(this).index() ).text();
    $(this).html( '<input type="text" placeholder="Search '+title+'" />' );
} );

My first column has been set to bFilter: false. So I don't want to show the <input> at the bottom of this column.
How can I do ?

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin

    Try:

    $('#example tfoot th:gt(0)')
    

    Allan

  • MartyFMartyF Posts: 14Questions: 5Answers: 1
    edited November 2014

    Thanks Allan, it works in this case. But how can I do if , for example, I have columns 3, 6 and 8 set to bFilter: false ?
    Isn't there a way to look at the columns' options via JS ? I like my DT options to be centralized in one script, and my pages do not have the same columns.

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    Answer ✓

    What you could do is add a class to the searchable columns and use that class in the selector.

    Unfortunately there isn't a public API to tell which columns are filterable at the moment. I'll be adding that in a future release.

    Allan

  • MartyFMartyF Posts: 14Questions: 5Answers: 1
    edited November 2014

    Thank you for your reply !
    Here is my modified code :

    $('#example tfoot th:not(.nofilter)').each( function () {
    ...
    

    And the corresponding columnDefs :

    "columnDefs": [
    { "name": "id", "targets": 0, "bFilter": false, "className": 'nofilter' },
    ...
    ]
    
This discussion has been closed.