bootstrap-select icon indicating copy to clipboard operation
bootstrap-select copied to clipboard

Include Optgroups (and all children) in Search

Open jtfairbank opened this issue 10 years ago • 10 comments

I'd like to have a version of live search that shows an optgroup and all its children if the search term matches the optgroup.

This would make working with large data sets that have parent -> child relationships a lot easier. It both shows the context that the optgroup provides, and allows users to filter by it.

For example, a selectpicker with optgroups:

Math
   - Intro
   - Algebra
   - Calculus
   - Number Theory

Science
   - Intro
   - Geology
   - Physics
   - Explosions Lab

Then I search for Math and the following is shown:

Math
   - Intro
   - Algebra
   - Calculus
   - Number Theory

Then I search for Intro and the following is shown:

Math
  - Intro

Science
  - Intro

Then I search for Explosions Lab and the following is shown:

Science
  - Explosions Lab

jtfairbank avatar Sep 08 '15 16:09 jtfairbank

Btw I checked and I am using the latest release (1.7.3).

jtfairbank avatar Sep 08 '15 16:09 jtfairbank

I just tried the showSubtext option, and found I can get this functionality by setting the subtext for each option to the optgroup's label. The functionality works as described above, however it adds a lot of repeated text.

jtfairbank avatar Sep 08 '15 16:09 jtfairbank

+1

klewin avatar Sep 15 '15 22:09 klewin

+1

kakoni avatar Nov 24 '15 13:11 kakoni

So as a workaround I use data-tokens. Example:

<select class="selectpicker" multiple data-live-search="true">
  <optgroup label="Condiments">
    <option data-tokens="condiments, mustard">Mustard</option>
    <option data-tokens="condiments, ketchup">Ketchup</option>
    <option data-tokens="condiments, relish">Relish</option>
  </optgroup>
</select>

kakoni avatar Jan 23 '16 10:01 kakoni

+1

m-hagberg avatar Jun 14 '16 14:06 m-hagberg

Can you please suggest, even i have the same requirement

avinashn-rapidd avatar Sep 20 '16 11:09 avinashn-rapidd

and now, there is any feature to support this issue? search with optgroup's label attribute? i mean not work with data-tokens attribute?

RandalTeng avatar Aug 23 '18 08:08 RandalTeng

and now, there is any feature to support this issue? search with optgroup's label attribute? i mean not work with data-tokens attribute?

Yeah that would be handy especially when using MVC and viewbags to populate dropdowns

jimbrew avatar Nov 19 '19 15:11 jimbrew

I am trying to use both data-token and data-subtext, but I am unable to search the group label. <select class="selectpicker" data-live-search="true" data-actions-box="true" multiple> <ng-container *ngFor="let blrareas of bngData['areas']"> <optgroup [attr.label]="blrareas['region']"> <ng-container *ngFor="let pinloc of blrareas['vicinity']"> <option [attr.data-tokens]="blrareas['region']" [attr.data-subtext]="pinloc['localities']">{{pinloc['pincode']}}</option> </ng-container> </optgroup> </ng-container> </select>

tlranjan avatar Feb 06 '24 06:02 tlranjan