【问题标题】:Looking for a way to use a select2 control with an internal filter widget of tablesorter寻找一种将 select2 控件与 tablesorter 的内部过滤器小部件一起使用的方法
【发布时间】:2014-04-14 00:45:35
【问题描述】:

内部过滤器小部件与此示例中概述的外部过滤器相对:

http://mottie.github.io/tablesorter/beta-testing/example-external-filters-using-select2.html

我正在寻找一种类似于前两个带有占位符的外部过滤器框的行为:AlphaNumeric 和 AlphaNumeric Tag,但我希望该行为在表格内。这是我尝试做的:

<th class="filter-select2" data-placeholder="select something">

这不起作用,但如果我将"filter-select2" 更改为"filter-select",那么它会起作用。

我正在寻找一种方法来破解/自定义现有的 tablesorter 行为以允许在内部使用 select2。我不太了解 JS 和库,无法自行尝试。

这是我用来初始化 tablesorter 库的 JavaScript sn-p。

$('#table1').tablesorter({
    theme : 'ice',
    cssInfoBlock : 'tablesorter-no-sort',
    widgets: ['zebra', 'stickyHeaders', 'filter']
});

【问题讨论】:

  • 比这要复杂一些...我正在编写一些代码来让 select2 与 filter formatter option 一起工作,但我还没有彻底测试过。当我有更多空闲时间时,我会看看我能做什么。
  • 嗨@Mottie,我明白并且可以等待。您不欠任何人任何东西,尽管您对改进和维护 tablesorter 的热情肯定受到其他程序员和我自己的赞赏。您是否考虑过为这个极具价值的图书馆募集 PayPal 捐款?
  • 这可能与这个问题并不完全相关,但我目前使用的是 selected,而不是 select2(只是因为我偶然发现了先选择)。我可以转储它并开始使用 select2。我想你开始支持一个而不是另一个是有原因的。任何cmets:stackoverflow.com/questions/13575531/…
  • 同样的原因...我遇到了第一个选择。哈哈。我现在确实更喜欢 select2,但我还有很多其他的事情要做,以至于我很难找到时间,或者记不起做这些小项目。

标签: jquery filter tablesorter jquery-select2


【解决方案1】:

我刚刚为select2 插件添加了一些过滤器格式化程序代码。按如下方式使用:

$('table').tablesorter({
  theme: 'blue',
  widthFixed: true,
  widgets: ['zebra', 'filter'],
  widgetOptions : {
    filter_reset : 'button.reset',
    filter_formatter : {
      // Alphanumeric (match)
      0 : function($cell, indx){
        return $.tablesorter.filterFormatter.select2( $cell, indx, {
          match : true, // adds "filter-match" to header
          cellText : 'Match: ',
          width: '85%'
        });
      }
    }
  }
});

【讨论】:

  • 谢谢您,先生,我打算在一周内尝试一下。
猜你喜欢
  • 2015-08-16
  • 2019-12-13
  • 1970-01-01
  • 2012-08-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-09-20
相关资源
最近更新 更多