stefanocudini / bootstrap-list-filter

Search widget to filter Bootstrap lists
https://opengeo.tech/bootstrap-list-filter/
MIT License
99 stars 31 forks source link

Documentation #27

Closed joshuaadickerson closed 8 years ago

joshuaadickerson commented 8 years ago

I would love to use this but it is missing documentation which makes it quite difficult.

I have a list with data-* attributes that I want to filter by their attributes but I can't find any examples or documentation on how to do that.

Thanks, Josh

joshuaadickerson commented 8 years ago

If there is a better way to do this, please tell me:

    $('#drivers').btsListFilter('#driver-search', {
        resetOnBlur: false,
        itemFilter: function(item, search_term) {
            var item = $(item);
            var search_term = search_term && search_term.replace(new RegExp("[({[^.$*+?\\\]})]","g"),'');
            var regSearch = new RegExp('^' + search_term, 'i');

            // These are the data attributes to check for the search term
            var data_attr = [
                'fname',
                'lname',
                'licnum'
            ];

            var found = false;

            $(data_attr).each(function (k, attr) {
                var text = item.data(attr);

                if (regSearch.test( text )) {
                    found = true;
                }
            });

            return found;
        }
    });
stefanocudini commented 8 years ago

Yes! Great! itemFilter can be an arbitrary function that return true or false like as javascript .filter() method: http://www.w3schools.com/jsref/jsref_filter.asp

Can you make new example page about this and send me a pull requets? please