本文介绍了选择过滤器时,Tablesorter 值应始终可见的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用表格排序器,只是想知道是否有办法在默认情况下始终显示值,而不管从过滤器选择列表中选择的过滤器如何.我尝试使用过滤器函数,但是在为具有过滤器选择的列添加过滤器函数后,它会丢失包含所有可用值的过滤器选择列表.

I am currently using table sorter and just want to know if there is a way to have a value by default always shows up regardless of the selected filter from the filter-select list. I tried using filter functions, but after I added a filter function for a column that has a filter-select, it loses the filter-select list with all of the available values.

例如,这是我尝试使用的过滤器函数,无论选择什么值,它都应该显示John":

For example, here is the filter function that I tried using, it should show "John" regardless of the values that are selected:

    0 : function(e, n, f, i, $r, c, data) {
      var x = e===f;
      var y = e==='John';
      var show = x|y;

      return show;
    },

我错过了什么吗?

推荐答案

在 JavaScript 中,OR 运算符需要两个竖线:

In javascript, the OR operator requires two vertical bars:

0 : function(e, n, f, i, $r, c, data) {
   var x = e===f;
   var y = e==='John';
   var show = x || y;

   return show;
 },

也许更好的方法是使用 filter_defaultFilter 选项 可以如下使用(demo):

Maybe a better method would be to use the filter_defaultFilter option which can be used as follows (demo):

$(function() {
  $('table').tablesorter({
    theme: 'blue',
    widgets: ['zebra', 'filter'],
    widgetOptions: {
      filter_defaultFilter: {
        // Ox will always show
        // {q} is replaced by the user query
        2: '{q}|Ox'
      }
    }
  });
});

另外,确保在标题单元格中包含过滤匹配"类名:

Also, make sure to include a "filter-match" class name in the header cell:

<th class="filter-match">...</th>

否则OR"查询默认为精确的单元格内容匹配.

otherwise "OR" queries default to exact cell content matches.

这篇关于选择过滤器时,Tablesorter 值应始终可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 22:21