Twitter Bootstrap Row Filter / Search Box

后端 未结 2 636
感动是毒
感动是毒 2021-01-30 15:35

I\'m having trouble finding a tutorial on how to create a simple search query, or row filter, for Twitter Bootstrap. I\'ve tried many, I\'m not sure if I\'m doing something wron

相关标签:
2条回答
  • 2021-01-30 15:38

    Here's what I use:

    $('input.filter').live('keyup', function() {
        var rex = new RegExp($(this).val(), 'i');
        $('.searchable tr').hide();
            $('.searchable tr').filter(function() {
                return rex.test($(this).text());
            }).show();
        });
    

    To use it, you just create a table, with a tbody with the class "searchable" and then an input with class "filter" somewhere on your page (I prefer to put them in a Bootstrap Popup behind a search icon).

    0 讨论(0)
  • 2021-01-30 15:58

    This is live example of solution provided by Filipp Lepalaan. Many thanks for this small and perfect code.

    Example

    $(document).ready(function () {
    
    (function ($) {
    
        $('#filter').keyup(function () {
    
            var rex = new RegExp($(this).val(), 'i');
            $('.searchable tr').hide();
            $('.searchable tr').filter(function () {
                return rex.test($(this).text());
            }).show();
    
        })
    
    }(jQuery));
    

    });

    0 讨论(0)
提交回复
热议问题