Tablesorter:不要将特定列值显示为过滤器

时间:2016-12-06 21:09:49

标签: tablesorter

有没有办法将列值删除为具有" filter-select"的列的过滤器?属性。

这是来自jsfiddle的@mottie的一个例子 http://jsfiddle.net/Mottie/856bzzeL/1085/。我刚刚添加了一个" filter-select"在列动物列上。有没有办法从下拉过滤器值中删除考拉

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'
      }
        }
    });
});

1 个答案:

答案 0 :(得分:0)

在这种情况下,您需要filter_selectSource option来操作select(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";
        });
      }
    }
  });
});