过滤基于通配符的引导JS表行列

时间:2021-09-28 22:21:01

I have created a table with bootstrap using the boostrapTable function. I am in need of trying to filter a table by a column, but I need to have a wildcard in place to just look for a specific string of Yes or No.

我使用boostrapTable函数创建了一个带引导程序的表。我需要尝试按列过滤表格,但我需要有一个通配符才能查找特定的“是”或“否”字符串。

From what I have read fnFilter for dataTables would do what I need, but I cant find the equivalent for bootstrapTable

从我所看到的fnFilter for dataTables将做我需要的,但我找不到bootstrapTable的等价物

It seems like this would be what would work for datatables, but does not work for bootstrap

看起来这将是适用于数据表的东西,但不适用于bootstrap

$('.spammy_links').click(function() {
    $table.fnFilter("^"+"search_string"+"$", column_name, true);
});

Here is what a bootstrap version of filtering looks like, but has no wild card options. This actually works but only of the record contains ONLY Yes or No

以下是过滤器的引导版本,但没有外卡选项。这实际上有效,但只有记录包含只有是或否

$('.spammy_links').click(function() {
    $table.bootstrapTable('filterBy', {
        indexed: 'Yes'
    });
});

Is there anything similar in bootstrap?

bootstrap中有类似的东西吗?

1 个解决方案

#1


I ended up finding a solution thanks to Twitter Bootstrap Row Filter / Search Box

我最终通过Twitter Bootstrap行过滤器/搜索框找到了解决方案

I altered the title a bit to be more descriptive.

我稍微修改了标题以便更具描述性。

All I needed to do what add this code which I altered a bit

所有我需要做的是添加我改变了一点的代码

$('tbody').addClass('searchable'); //<-- Add class to tbody for filter below
$('.spammy_links').on('click', function() {
    var rex = new RegExp('No', 'i');
    $('.searchable tr').hide();
    $('.searchable tr').filter(':has(td:nth-child(2):contains("No"))',function() {
        return rex.test($(this).text());
    }).show();
});

#1


I ended up finding a solution thanks to Twitter Bootstrap Row Filter / Search Box

我最终通过Twitter Bootstrap行过滤器/搜索框找到了解决方案

I altered the title a bit to be more descriptive.

我稍微修改了标题以便更具描述性。

All I needed to do what add this code which I altered a bit

所有我需要做的是添加我改变了一点的代码

$('tbody').addClass('searchable'); //<-- Add class to tbody for filter below
$('.spammy_links').on('click', function() {
    var rex = new RegExp('No', 'i');
    $('.searchable tr').hide();
    $('.searchable tr').filter(':has(td:nth-child(2):contains("No"))',function() {
        return rex.test($(this).text());
    }).show();
});