简体   繁体   English

yadcf custom_filter-如何查找不为null和不为空的值?

[英]yadcf custom_filter - how to find not null and not empty values?

I want to filter on the column - a value that is not null and not empty. 我想对列进行过滤-一个不为null且不为空的值。

 yadcf.init(table, [        
    {
        column_number: 4,
        filter_type: 'custom_func',
        custom_func: myCustomFilterFunction,
        data: [ {
            value: 'empty',
            label: 'Empty'
        },
            {
            value: 'notempty',
            label: 'NotEmpty'
            }
        ],
        filter_default_label: "All"
    }
]);  

function myCustomFilterFunction(filterVal, columnVal) {
    var found;
    if (columnVal === '') {
        return true;
    }
    switch (filterVal) {
        case 'empty':
            found = columnVal.search(null);
            break;
        case 'notempty':
            found = columnVal.lenght > 0;
            break;
        default:
            found = 1;
            break;
    }
    if (found !== -1) {
        return true;
    }
    return false;
}

Empty values filtering works . 空值过滤有效。 But how to filter not empty and not null values ? 但是如何过滤不为空和不为空的值呢? columnVal.lenght > 0 does not work columnVal.lenght> 0不起作用

There are many ways to accomplish this, here is a one way... 有很多方法可以做到这一点,这是一种方法...

function myCustomFilterFunction(filterVal, columnVal) {
    var found = false;
    debugger;
    switch (filterVal) {
        case 'empty':
            found = columnVal ? false : true;
            break;
        case 'notempty':
            found = columnVal ? true : false;
            break;
        default:
            break;
    }
    return found;
}

See working jsfiddle 参见工作jsfiddle

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM