Bootstrap-Table自定义过滤算法

问题描述 投票:0回答:1

我正在尝试使用 Bootstrap-Table 来显示我的数据,我想过滤指定单元格为空的行,但我不希望它们显示。

$('#tableId').bootstrapTable('refreshOptions', {
    filterOptions: {
        filterAlgorithm: "not"
    }
});

$('#@tableId').bootstrapTable('filterBy', {"specifiedCell":""});

遗憾的是,filterAlgorithm 不支持上面代码中的

not

我应该在filterAlgorithm前面写什么来使用自定义过滤器?

bootstrap-table
1个回答
1
投票

我在互联网上没有看到任何关于它的好的解释,但通过测试我了解到自定义过滤器模板是这样的:

$('#tableId').bootstrapTable('refreshOptions', {
    filterOptions: {
        filterAlgorithm: function (row, filter) {
            if(row['specifiedCell'] != filter['specifiedCell']){ //check row or row[cell] condition by `filter`
                return true;//it will the `row` will display.
            } else {
                return false;//it wont show the `row`
            }
        }
    }
});

$('#@ViewBag.dynamicData["tableId"]').bootstrapTable('filterBy', {
    "specifiedCell":""
});

在上面的代码中,我使用过滤器检查了行中的指定单元格,其中包含不应该出现在表中的值,因此通过在不在过滤器中返回 true 来创建自定义

not
过滤器。

© www.soinside.com 2019 - 2024. All rights reserved.