Tablesorter value should always be visible when choosing a filter

荒凉一梦 提交于 2019-12-11 06:27:49

问题


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.

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;
    },

Am I missing something?


回答1:


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;
 },

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>

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



来源:https://stackoverflow.com/questions/40899404/tablesorter-value-should-always-be-visible-when-choosing-a-filter

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