Tablesorter:按多个(但不是全部)列过滤 [英] Tablesorter: filtering by multiple, but not all, columns

查看:33
本文介绍了Tablesorter:按多个(但不是全部)列过滤的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用带有外部过滤器的 tablesorter.(ctrl-F 'filter_external') 在链接页面上.来自文档:

I'm using tablesorter with an external filter. (ctrl-F 'filter_external') on the linked page. From the docs:

这些外部输入有一个要求,它们必须有一个data-column="#",其中 # 以列为目标(从零开始的索引),指向要搜索的特定列.

These external inputs have one requirement, they must have a data-column="#", where the # targets the column (zero-based index), pointing to a specific column to search.

<input class="search" type="search" data-column="0" placeholder="Search first column">

如果要搜索所有列,请使用更新后的任何匹配"方法,将数据列值设置为all":

If you want to search all columns, using the updated "any match" method, set the data column value to "all":

<input class="search" type="search" data-column="all" placeholder="Search entire table">

我想要的是将我的外部过滤器应用于一组列(多于一个,少于全部).理想情况下,html 可能如下所示:

What I'd like is to apply my external filter to a collection of columns (more than one, less than all). Ideally, the html could look something like this:

<input class="search" type="search" data-column="0,1" placeholder="Search first two columns">

或者这个:

<input class="search" type="search" data-column="0" data-column="1" placeholder="Search first two columns">

(第二个是有效的 html 吗?)

(Is the second one even valid html?)

我一直在查看 tablesorter 文档,但我没有运气应用我想要的排序.我尝试的一种解决方法是向用户呈现单个输入,并将其写入绑定到各自列的隐藏输入:

I've been up and down the tablesorter docs and I haven't had any luck applying the sort that I want. One workaround that I attempted was to present a single input to the user and have it write to hidden inputs which were bound to their respective columns:

<input class="search" type="search" placeholder="Search first two columns">
// javascript populates the hidden inputs as the user types in the visible one
<input class="search" type="search" data-column="0" style="display: none;">
<input class="search" type="search" data-column="1" style="display: none;">

这个有效",除了它现在与"从每个单独的过滤器中进行过滤,这样两列都必须匹配搜索词才能使行保持可见,而不是与要保持行的搜索词匹配的 EITHER 列可见的.data-column="all" 选项 'OR 是搜索 - 这就是我想要的.

This 'works', except that it now 'AND's the filtering from each individual filter, so that BOTH columns have to match the search term for the row to remain visible rather than EITHER column matching the search term for the row to remain visible. The data-column="all" option 'OR's the searches - this is what I want.

推荐答案

这个建议很好!

我刚刚添加了在外部搜索输入中包含多列的功能.此更改目前仅在 存储库的工作分支

I just added the ability to include multiple columns in an external search input. This change is currently only available within the working branch of the repository

通过此更改,您可以包含一个范围或多个以逗号分隔的列(演示):

With this change, you can include a range, or multiple columns separated by commas (demo):

<input type="search" class="search" data-column="0-1,3,5-7,9">

注意:

  • 此输入的行为与带有 data-column="all" 的输入相同,其中范围"、notMatch"和运算符"搜索将被忽略.
  • 如果存在多个输入,则最后一次搜索将覆盖之前的所有搜索.
  • 忽略数据列属性中的所有空格.
  • This input behaves the same as an input with data-column="all" in that "range", "notMatch" and "operators" searches are ignored.
  • If multiple inputs exist, the last search will override all previous searches.
  • All spaces in the data-column attribute are ignored.

这篇关于Tablesorter:按多个(但不是全部)列过滤的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆