Individual columns search based on the 'Searchable' value of the col

Individual columns search based on the 'Searchable' value of the col

jeanjean Posts: 12Questions: 5Answers: 0

Looking at https://datatables.net/examples/api/multi_filter.html
What would be the correct way to show those inputs only for col which are actually defined as searchable?

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,759Questions: 1Answers: 10,111 Site admin

    There isn't a public API in DataTables to tell if a column is searchable or not (from the columns.searchable flag) - probably an oversight on my part that.

    However, what you could do is simply add a "searchable" class to searchable columns and then do a $().hasClass() check on the element to see if it is searchable or not.

    Allan

  • jeanjean Posts: 12Questions: 5Answers: 0

    Thanks,
    Yes that was the way I was doing it but it still need to change that information in two place (JS definition of the dtable and html) when we change what col are searchable.
    It's manageable but would be nice to be able to factorize that and make it automatic.

    Thanks for the quick reply!
    jean

  • allanallan Posts: 61,759Questions: 1Answers: 10,111 Site admin
    Answer ✓

    Agreed! I'll look at providing a plug-in that gives that information.

    Allan

  • jeanjean Posts: 12Questions: 5Answers: 0

    Thanks!

  • tangerinetangerine Posts: 3,350Questions: 37Answers: 394

    What would be the correct way to show those inputs only for col which are actually defined as searchable?

    Allan - is there any news on this?

    Having set up initial params thus (for example):

    columnDefs: [ 
      { searchable: false, targets: [ 3] },  
    

    the most logical thing for adding text search inputs would be (pseudo code):

    $("#datatable tfoot th").each( function ( i ) {
      if ( *current-column-searchable* )
      *add-text-search-input*
    )};
    

    Maybe it's already possible, but I haven't managed to figure it out.

  • allanallan Posts: 61,759Questions: 1Answers: 10,111 Site admin

    Basically you need a-priori knowledge of this fact as I've not yet implemented an API method to get this information at run time.

    So there are basically two options:

    1. Possibly the best option is to use columns.className and add a class "searchable" to the columns which are searchable. Then use that in your selector.
    2. A less attractive option is to keep an array of column indexes which are searchable (pre-programmed) and loop over that.

    Allan

  • tangerinetangerine Posts: 3,350Questions: 37Answers: 394

    OK - thanks!

This discussion has been closed.