【问题标题】:Tablesorter filter-onlyAvailTablesorter filter-only 可用
【发布时间】:2015-08-19 18:53:17
【问题描述】:

我使用 gem jquery-tablesorter-rails 的 tablesorter (mottie's fork v2.23.0)

我有一个表,我在其中使用类 filter-select filter-onlyAvail 来获取列中仅可用选项的下拉列表。

最近我在列中添加了 jeditable,该列向单元格添加了一个脚本标记(也可能将值嵌入到跨度中),如下所示:

<td>                  
  <span class="editable" data-id="15" data-name="user[route]" title="Click to edit..">1</span>
  <script type="text/javascript">
    ...script for jeditable....
  </script>
</td>

结果是选择过滤器下拉列表显示了值的所有变体,包括脚本内容。

我尝试使用添加了过滤器匹配类的 filter_selectSource,但过滤器的内容很常见(如 1,2 99 等)我在脚本中得到了很多错误命中。

关于如何在选择人口和搜索结果中放弃脚本标签内容的任何指针?

【问题讨论】:

    标签: tablesorter


    【解决方案1】:

    我最终在要用于过滤和排序的元素上使用了 data-text="value"。

    在我的例子中是标签。

    但是,这不会更新 tablesorter 的过滤器值或搜索更新单元格的内容。

    【讨论】:

    • 更新单元格后 - 我假设您使用的是updateCell method? - 使用$('table').trigger('search', false) 更新搜索。
    【解决方案2】:

    使用filter_selectSource option 填充过滤器下拉列表。

    设置为数组

    filter_selectSource : {
      0 : [ "abc", "def", "ghi", "xyz" ]
    }
    

    或函数:

    filter_selectSource : function(table, column, onlyAvail){
      // get an array of all table cell contents for a table column
      var array = $.tablesorter.filter.getOptions(table, column, onlyAvail);
      // manipulate the array as desired, then return it
    
      return array;
    }
    

    另外,由于动态排序的表格行中的内联脚本并不理想,请查看editable widget,它使用 HTML5 contenteditable 来允许用户交互。

    【讨论】:

    • 感谢@Mottie 的快速回复。遗憾的是,filter_selectSource 函数无法正确过滤内容。我最终在 td 标记上使用了数据文本,直到我实际在线更新值为止。接下来是在 jeditable 中编写回调。我会考虑改用可编辑的小部件。
    猜你喜欢
    • 1970-01-01
    • 2012-08-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-26
    • 2022-08-18
    • 2014-02-03
    相关资源
    最近更新 更多