Tablesorter: filtering by multiple, but not all, columns

我们两清 提交于 2019-12-11 09:13:58

问题


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

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">

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">

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">

or this:

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

(Is the second one even valid html?)

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;">

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.


回答1:


That's a great suggestion!

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">

Note:

  • 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.


来源:https://stackoverflow.com/questions/26470602/tablesorter-filtering-by-multiple-but-not-all-columns

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!