Disable search when using fnSetColumnVis()?

Disable search when using fnSetColumnVis()?

ChristinaChristina Posts: 4Questions: 0Answers: 0
edited July 2009 in General
First off - thank you for your amazing plugin! It is truly remarkable!

I'm working with version.5.0 beta 11. Since my table is large, I have a series of checkboxes so users can toggle the visibility of the columns. I'm using the fnSetColumnVis() function for this. However, when a column of data is hidden, I don't want it searchable. Is there anyway I can toggle bSearchable in addition to the visibility?

Best regards,
Christina

Replies

  • allanallan Posts: 63,535Questions: 1Answers: 10,475 Site admin
    Hi Christina,

    Just having the column as hidden doesn't stop them from being searchable, as you are seeing. You'll need to set the bSearchable property for the column in question (use aoColumn[index].bSearchable). Following that you'll need to rebuilt the search array. Easiest way to do that is to call fnDraw().

    Regards,
    Allan
  • DaveBurnsDaveBurns Posts: 17Questions: 0Answers: 0
    Allan - Is this still the preferred approach? Wondering since this thread is 2.5 years old. If so, I'm a bit confused on your suggestion. I see in the doc for ColVis that I'd define my fnStateChange function. Once in there, is there an API to set bSearchable for a given column? You seem to imply by the above that there's no API, it's just a property, but I'm unclear how to get at it. Is it just myTable.aoColumn[index].bSearchable = true/false?

    Thanks.
  • DaveBurnsDaveBurns Posts: 17Questions: 0Answers: 0
    Adding the following to my dataTable init options works for me. Would be good to hear if this is the "approved" approach though. Thanks!

    [code]
    "oColVis": {
    "fnStateChange": function( iColumn, bVisible ) {
    report.dataTableSettings[ 0 ].aoColumns[ iColumn ].bSearchable = bVisible;
    }
    }
    [/code]
  • allanallan Posts: 63,535Questions: 1Answers: 10,475 Site admin
    The looks good to me. The only thing I would suggest is that rather than using "report.dataTableSettings[ 0 ]" use this.s.dt - 'this' is the ColVis object instance and this.s.dt is the settings object for the DataTable. The two are equivalent if you have only 1 table on the page, but it falls apart if you have 2 or mow.

    Allan
This discussion has been closed.