2016-12-06 77 views
1

有没有办法在具有“filter-select”属性的列上删除列值作为过滤器。Tablesorter:不显示特定列值作为过滤器

下面是jsfiddle中的@mottie示例 http://jsfiddle.net/Mottie/856bzzeL/1085/。我只在列动物列中添加了“过滤器选择”。有没有一种方法,例如删除考拉从下拉筛选器的值?

HTML

<table class="tablesorter"> 
<thead> 
    <tr> 
     <th>AlphaNumeric</th> 
     <th>Numeric</th> 
     <th class="filter-match filter-select">Animals</th> 
     <th>Sites</th> 
    </tr> 
</thead> 
<tbody> 
    <tr> 
     <td>abc 123</td> 
     <td>10</td> 
     <td>Koala</td> 
     <td>http://www.google.com</td> 
    </tr> 
    <tr> 
     <td>abc 1</td> 
     <td>234</td> 
     <td>Ox</td> 
     <td>http://www.yahoo.com</td> 
    </tr> 
    <tr> 
     <td>abc 9</td> 
     <td>10</td> 
     <td>Girafee</td> 
     <td>http://www.facebook.com</td> 
    </tr> 
    <tr> 
     <td>zyx 24</td> 
     <td>767</td> 
     <td>Bison</td> 
     <td>http://www.whitehouse.gov/</td> 
    </tr> 
    <tr> 
     <td>abc 11</td> 
     <td>3</td> 
     <td>Chimp</td> 
     <td>http://www.ucla.edu/</td> 
    </tr> 
</tbody> 

脚本:的tablesorter

/* Documentation for this tablesorter FORK can be found at 
* http://mottie.github.io/tablesorter/docs/ 
*/ 
// See http://stackoverflow.com/q/40899404/145346 
$(function(){ 
    $('table').tablesorter({ 
     theme: 'blue', 
     widgets: ['zebra', 'filter'], 
     widgetOptions: { 
      filter_defaultFilter: { 
     // Ox will always show 
     2: '{q}|Ox' 
     } 
     } 
    }); 
}); 

回答

0

在这种情况下,您将需要filter_selectSource option操纵的选择(demo

选项
$(function() { 
    $('table').tablesorter({ 
    theme: 'blue', 
    widgets: ['zebra', 'filter'], 
    widgetOptions: { 
     filter_defaultFilter: { 
     // Ox will always show 
     2: '{q}|Ox' 
     }, 
     filter_selectSource: function(table, column, onlyAvail) { 
     // get an array of all table cell contents for a table column 
     var array = $.tablesorter.filter.getOptions(table, column, onlyAvail); 
     // remove Koala (multiple entries) from array 
     return $.grep(array, function(animal) { 
      return animal !== "Koala"; 
     }); 
     } 
    } 
    }); 
}); 
相关问题