【问题标题】:Exact filter when multiple values/html elements in a cell单元格中有多个值/html元素时的精确过滤器
【发布时间】:2017-03-06 11:10:44
【问题描述】:

这可能与特定于 YADCF 的 DataTables 相关的更多,但如果该功能不存在,我在这里提出它是一种明显的增强。

我有一列可以包含多个值“标签”,类似于 YADCF 示例。允许按这些标签进行过滤的过滤器会正确生成。

JSFiddle 这里https://jsfiddle.net/wallacio/622704ep/6/

请参阅标题为 AreaRig 的列(请原谅可怕的颜色...!)

如果我只想查看South的事件,我需要使用filter_match_mode: "exact"(排除西南、东南等地的事件)

有一个包含标签“South”和“South East”的事件(未过滤视图中的第 8 个) Event containing South and South East tags

当过滤“South”时,不会出现此事件,可能是因为确切的过滤器匹配的是整个单元格的内容,而不是匹配其中的每个离散的 HTML 元素。

我可以将 filter_match_mode 更改为“包含”,但这会导致出现标记为“东南”等的事件,这是不可取的。

我已经对源进行了拖网搜索,可以看到在生成过滤器选项时考虑到了这一点,但在过滤时显然没有考虑到这一点,这就是为什么我想知道这是否是由 DataTables 过滤器的实现方式造成的限制。

【问题讨论】:

    标签: yadcf


    【解决方案1】:

    您可以使用filter_type: 'custom_func', 并为该特定列编写自己的过滤逻辑

    column_number: 0,
    filter_type: 'custom_func',
    custom_func: myCustomFilterFunction,
    data: ['one', 'two', 'three']
    

    myCustomFilterFunction 看起来像

    function myCustomFilterFunction(filterVal, columnVal) {
            var found = false;
            if (columnVal === '') {
                return true;
            }
            switch (filterVal) {
            case 'one':
                found = //some logic goes here
                break;
            case 'two':
                found = //some logic goes here
                break;
            case 'three':
                found = //some logic goes here
                break;
            default:
                found = false;
                break;
            }
    
            if (found) {
                return true;
            }
            return false;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-11-05
      • 1970-01-01
      • 2018-05-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多