选择过滤器时,Tablesorter 值应始终可见

编程入门 行业动态 更新时间:2024-10-25 16:25:44
本文介绍了选择过滤器时,Tablesorter 值应始终可见的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

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

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 值应始终可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-05-01 11:18:34,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1408869.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:过滤器   Tablesorter

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!