Skip to content
This repository has been archived by the owner on Nov 3, 2020. It is now read-only.

Support custom filtering #56

Closed
yoeriboven opened this issue May 7, 2018 · 2 comments
Closed

Support custom filtering #56

yoeriboven opened this issue May 7, 2018 · 2 comments
Labels

Comments

@yoeriboven
Copy link

It might be a good idea to let the user do the filtering. Currently I'm working on a project in which I want the search to be done in the value of the option or in the text with startsWith as the option.

This could be done like this:

$('.selectpicker').on('typed.bs.select', function (input) {
  // Filter results here
  	
  return results; // Array of results
});

Any suggestions?

@devjerry
Copy link

I'm in similar need.

In addition to setting 'startsWith' or 'contains' in liveSearchStyle option, there should be an option to pass custom function for filtering.

Something similar as https://select2.org/searching

Example:

Let's say I have following selectbox:

<select class="selectpicker" data-live-search="true">
    <option value="1">Paris - Black office</option>
    <option value="2">Paris - Red office</option>
    <option value="3">London - Black office</option>
    <option value="4">London - Red office</option>
</select>

After typing don bla I would like to have London - Black office in search results. So I would write my custom filtering function like this:

$('.selectpicker').selectpicker({
    liveSearchStyle: function(searchTerm, item) {
        return searchTerm.toLowerCase().split(' ').every(function(word) {
            return item.toLowerCase().indexOf(word) !== -1;
        });
    }
});

In the example item parameter represented current text of <option>. I would imagine it could be an object containing different parameters of current item in iteration (e.g. it's index, <option> text, <option> value, if it's inside <optgroup>, ...).

@ghost
Copy link

ghost commented Aug 21, 2018

This issue was moved by caseyjhol to snapappointments/bootstrap-select#2042.

@ghost ghost closed this as completed Aug 21, 2018
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants