Using a shared ColVis control on more than two tables?

Using a shared ColVis control on more than two tables?

bbrotherbbrother Posts: 3Questions: 1Answers: 0
edited April 2015 in Free community support

Hi,

I am investigating/learning about DataTables and I have the ColVis example for "Two tables with shared controls" working. However, I cannot seem to determine via the forum or via experimentation whether or not ColVis can be shared across more than two tables. Is that possible? I'm also a bit new to jQuery.

Here is an example with three tables. https://jsfiddle.net/whnju7u8/1/
ColVis effects the first two tables while the third remains unchanged.
The second column on all tables is initially hidden.

Thanks.

This question has an accepted answers - jump to answer

Answers

  • bbrotherbbrother Posts: 3Questions: 1Answers: 0

    My understanding is that the expression :gt(0) should select all elements at an index greater than index within the matched set. However, in this case, it stops iterating after the first two tables.

        tables.table(0).on('column-visibility', function ( e, settings, colIdx, visibility ) {
            tables.tables(':gt(0)').column( colIdx ).visible( visibility );
    } );
    

    Thanks in advance..

  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin
    Answer ✓

    This is the first time that the plural nature of the API has caught me out - after a bit of debugging I realised that the column() singular method was being used. The result is that only a single column from a single table is being selected when you use it.

    Simply using columns() allows it to work as expected: https://jsfiddle.net/whnju7u8/2/ .

    Something I need to update in the documentation (and remember)!

    Allan

  • bbrotherbbrother Posts: 3Questions: 1Answers: 0
    edited April 2015

    :-) well, with you being an author of this amazing library, I simply lay roses at your feet and offer my many thanks.

    Bill

This discussion has been closed.