Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter by option attribute. #1079

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

kirimaks
Copy link

I had a case when I was need to search in selector by some value but in the same time I couldn't show those values in the selector. For example I have a list of users and my users have some similar attribute like department or every user has a unique id and I want to make search by this id but in the option or opt group I should display another information and cannot display the values which I want to user for search. I couldn't search by values also because the list was dynamically rebuild and it was hard to select values dynamically. I hope that makes sense.

I wanted to be able to define selector like this

   <select id="example-getting-started" multiple="multiple">
        <optgroup label="Group 1">
            <option value="cheese" data-filtering="cheese">Cheddar</option>
        </optgroup>
        <optgroup label="Group 2">
            <option value="tomatoes" data-filtering="vegetables">Tomatoes</option>
        </optgroup>
        <optgroup label="Group 2">
            <option value="mozarella" data-filtering="cheese">Mozzarella</option>
        </optgroup>
        <optgroup label="Group 3">
            <option value="mushrooms">Mushrooms</option>
        </optgroup>
        <optgroup label="Group 3">
            <option value="pepperoni">Pepperoni</option>
        </optgroup>
        <optgroup label="Group 4">
            <option value="onions" data-filtering="vegetables">Onions</option>
        </optgroup>
    </select>

So after that I can search values by "cheese" or "vegetables" and I don't have to add "cheese" or "vegetables" to every item (which would be look ugly). I could add those values to every "value" attribute of the options but then the method like .val() or .multiselect('select', val) would be broken (in case if I need to get unique values of objects in the list).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant