Search code examples
jquerytablesorter

Dynamic Columns default filter TableSorter


I currently have a table that has a dynamic column, let's say based from the example below on jsfiddle, the AlphaNumeric column will only be visible based on a value of a variable(logic not included).

http://jsfiddle.net/Mottie/856bzzeL/1088/

Now this poses problems with the filter_defaultFilter widget option since it's based on the column number. If I have a column that becomes hidden - the default filter won't apply to the specified column number since the column index has change

filter_defaultFilter: {
    // Ox will always show
    2:{q}|Ox
 }

Is there a way to implement a logic behind the default filter to dynamically select the column number? or even use a column id or class to set a default filter?

filter_defaultFilter: {
    // Ox will always show
    if(true) {
        2: '{q}|Ox'
    } else {
        1: '{q}|Ox'
    }
  }

OR

  filter_defaultFilter: {
    // Ox will always show
     [column.id]: '{q}|Ox'
  }

Solution

  • The filter_defaultFilter option does allow you to set the value by column class name or ID. In the example, change the column zero-based index 2 to '.animals' (demo):

    filter_defaultFilter: {
      // Ox will always show
      '.animals': '{q}|Ox'
    }