Search code examples
javascriptjquerytablesorter

data-column ranges in columnSelector (Mottie's Tablesorter)


It seems that contrary to the behavior described here Tablesorter: filtering by multiple, but not all, columns , data-column ranges can't be applied in columnSelector.

For example, using $( "input[data-column='0']" ).attr("data-column", "0-5"); will indeed modify the data-column attribute of the first selector to 0-5 but it will continue to hide only the first column. Use case:

|-------------------------------|------------------------------|
|        Super header 1         |        Super header 2        |
|---------------|---------------|--------------|---------------|
| First header  | Second header | Third header | Fourth header |
|---------------|---------------|--------------|---------------|
|    Content    |    Content    |   Content    |   Content     |
|    Content    |    Content    |   Content    |   Content     |
|---------------|---------------|--------------|---------------|

In this example, the content is retrieved by Ajax and I'm trying to hide any of the super headers with a columnSelector that displays only them.


Solution

  • The column selector widget is completely separate from the filter widget, so that comparison won't work in this case. I could make some code changes to accept a range of columns, but then you would need to always build a custom popup in order to use it.

    I think what you desire is the refreshColumnSelector method which can be used to hide specific columns. Use it as follows:

    $('table').trigger('refreshColumnSelector', [ [0,1,2,3,4,5] ]);
    

    Sorry, it does not accept a range string.