running-coder / jquery-typeahead

Javascript Typeahead (autocomplete) plugin with more than 50 options and callbacks.
http://www.runningcoder.org/jquerytypeahead/
MIT License
544 stars 121 forks source link

It is possible to populate dropdown using same object key used in groups? #70

Closed sdillinger closed 8 years ago

sdillinger commented 9 years ago

If I provide a string (key) to the groups option - for example, 'division' in the hockey example, the query result sorts and groups by the values it finds.

I want to also filter by those same values using the dropdown. But I can't find a way to associate the two. In the example the dropdown values are 'hard coded' via an array.

Is it possible to associate groups and dropdown so that the dropdown values are the same values from groups?

If not I'd like to suggest it as a new feature as it would be uber-useful for situations where the group values are not known in advance, but are found via a key lookup (as works in groups).

Perhaps it would be a straight-forward hack as you already have the values in context if the user provided a key to the groups option.

running-coder commented 9 years ago

Hey sdillinger,

sounds like a great plan, perhaps it should have been like this from the get-go

running-coder commented 8 years ago

I've started working on it thinking it was a great idea to realize 2 hours after that in the case of dynamic data it would not work because only a subset of items is received at a time (10 items only for example) and would not offer all the available groups. This option to "self discover groups" only works if the data is all gathered at once... Might consider allowing the system to have both possibilities but not sure if it would lead to confusion...

// Regular dropdownFilter, fits for dynamic & static data
dropdownFilter: [
    {
        key: 'conference',
        value: 'Western',
        display: '<strong>Western</strong> Conference'
    },
    {
        key: 'conference',
        value: 'Eastern',
        display: '<strong>Eastern</strong> Conference'
    },
    {
        value: '*',
        display: 'All Teams'
    }
],

// Static data only, self discovering groups
dropdownFilter: {
    key: 'division',
    template: '<strong>{{division}}</strong> division',
    all: 'All Teams'
},
sdillinger commented 8 years ago

It's been awhile since I've had my head around this...

In my particular use case the data was static, but I see the issue re: dynamic data.

IMO it's pretty powerful and useful functionality, so it may be worth the uptick in complexity...

running-coder commented 8 years ago

Yea mb it's been a while, I've finally got some free time to clean the backlog. Alright will implement both ways. Will probably update the group option parameters also to accept the same object structure instead of an array where index 0 is assumed group and index 1 assumed template.

// Old way (not intuitive)
group: ['division', '<strong>{{group}}</strong> division'],

// New way
group: {
    key: 'division',
    template: '<strong>{{division}}</strong> division'
},
running-coder commented 8 years ago

should be good with the upcoming 2.5.0 version, documentation will be updated upon release

sdillinger commented 8 years ago

Great. Thanks for all you do.

On Mon, Apr 4, 2016 at 8:29 PM, Tom Bertrand notifications@github.com wrote:

should be good with the upcoming 2.5.0 version, documentation will be updated upon release

— You are receiving this because you authored the thread. Reply to this email directly or view it on GitHub https://github.com/running-coder/jquery-typeahead/issues/70#issuecomment-205581115

Steve Dillinger Founder & CEO

steve@ciqlabs.com (312) 804-4799

www.getclassroomiq.com

https://www.youtube.com/watch?v=lfTvwbFXVlg

running-coder commented 8 years ago

yw, this task was quite challenging at different levels. thanks for suggesting!