column.searchable does not seem to work like column.visible

column.searchable does not seem to work like column.visible

felixgillfelixgill Posts: 24Questions: 7Answers: 0

Hello,

I was trying to implement a column hiding feature and thanks to the example it works great.

$(document).ready(function() {
    var table = $('#example').DataTable( {
        "scrollY": "200px",
        "paging": false
    } );
 
    $('a.toggle-vis').on( 'click', function (e) {
        e.preventDefault();
 
        // Get the column API object
        var column = table.column( $(this).attr('data-column') );
 
        // Toggle the visibility
        column.visible( ! column.visible() );
      
        // my addition
       column.searchable( ! column.searchable() );
    } );
} );

However I added a small piece... the ability to once the column is visible to make it searchable as well... and this throws an error: Uncaught TypeError: undefined is not a function ... I checked the API -- yeah that doesn't exist in the way I am trying to use it.

My question: Any ideas on how to do this ? make a column searchable after table has been initialized?

This question has an accepted answers - jump to answer

Answers

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

    There is no column().searchable() method. Did you find something in the documentation that suggests there is? If so, could you point me at it so I can remove it.

    Having said that, it probably is a good idea for me to add it - it makes sense...

    Allan

  • felixgillfelixgill Posts: 24Questions: 7Answers: 0

    Hi Allan,

    No nothing in the documentation states this... I was stating how my train of thought was flawed.

    My question is, does anyone know of a way to change the searchable state of a column after the table has been initialized?

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

    a way to change the searchable state of a column after the table has been initialized?

    There is no option to do that I'm afraid. I don't think there is even a hack using the private methods that would do that (well... there probably is, but I don't know what it is without researching it, and I'm traveling atm so a bit tricky!).

    Out of interest, why would you want to change that state? That's why that option isn't available atm - I couldn't think of a reason why it would be needed - and thus there was no need to add the code overhead for it.

    Allan

  • felixgillfelixgill Posts: 24Questions: 7Answers: 0

    A way around came to me.

    I am using dynamically hidden columns.

    I will turn all columns to searchable=true
    then all columns that are hidden will become null values via javascript filter
    as columns become visible I will un-null the values. The down side is creating a copy of the objects in memory.-- especially since I have a pretty large data set.

This discussion has been closed.