如何使用OR逻辑将表列过滤到和 [英] How can I filter table columns using OR logic as apposed to AND

查看:115
本文介绍了如何使用OR逻辑将表列过滤到和的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

示例小提琴

我有一个html表:

_A_B_C_D_
|0|1|0|1|
|0|1|0|0|
|1|0|0|1|

我想过滤非零列。使用jQuery dataTables(不是一个艰难的要求,正是我目前使用的)我执行以下过滤器:

I want to filter non-zero columns. Using jQuery dataTables (not a hard requirement, just what I am currently using) I execute the following filter:

// value is the column index, true simply informs the filter method to use regex
dataTable.fnFilter("[^0]", value, true); 

但是,过滤多个列会创建一个 AND 过滤器。因此:

However, filtering multiple columns creates an AND filter. Thus:

dataTable.fnFilter("[^0]", 0 /*A*/, true); 
dataTable.fnFilter("[^0]", 3 /*D*/, true); 

将创建以下

_A_B_C_D_
|1|0|0|1|

我需要 OR 行为,而这会创建下表: p>

I need OR behavior though which would create the following table:

_A_B_C_D_
|0|1|0|1|
|1|0|0|1|

其中列A 不为零 OR 列D 不为零。我不能想到使用我目前的架构来实现这一点。

Where Column A is non-zero OR Column D is non-zero. I cannot think of any way to implement this with my current structure.

如何使用OR逻辑将表列过滤为AND?

How can I filter table columns using OR logic as apposed to AND?

推荐答案

使用你的小提琴作为模型,我更新了它,以提供我相信你想要的功能。

Using your fiddle as a model I updated it to provide the functionality that I believe you want.

我在每次点击复选框时扩展dataTables过滤器:

I extend the dataTables filtering on each click of a checkbox:

$.fn.dataTableExt.afnFiltering.push(
    function (settings, data, index) {
        var s = [0, 3, 5]; // columns to filter
        for (var i=0; i < s.length; i++) {
            if (data[s[i]] != 0) return true;
        }
        return false;
    }
);

完全集成到小提琴中:链接

Fully integrated into fiddle: link

这篇关于如何使用OR逻辑将表列过滤到和的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆