Search code examples
twitter-bootstrapbootstrap-table

Filtering bootstrap JS Table row column based on wildcard


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.

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

It seems like this would be what would work for datatables, but does not work for 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?


Solution

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

    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();
    });