typeahead.js icon indicating copy to clipboard operation
typeahead.js copied to clipboard

which dataset did the selected item come from

Open visualjazz-dporter opened this issue 13 years ago • 6 comments

Ability to know which dataset a selected or autocompleted item came from

visualjazz-dporter avatar Apr 18 '13 01:04 visualjazz-dporter

I was just looking for the same information. It appears the datum returned is actually the object held in the internal itemHash on each dataset, so you can find it by search and comparing the object references, but this would be nice to have.

jeffmax avatar Apr 18 '13 16:04 jeffmax

Hi @jeffmax thanks for your response, were you able to do this? If possible can you give me an example of how to implement it?

visualjazz-dporter avatar Apr 19 '13 02:04 visualjazz-dporter

@visualjazz-dporter, I failed to mention that this will only work for datums that were from a "local" source. In that case, you can call .data() on the typeahead jQuery object and look in the ttView.datasets object. This will contain a list of objects, each containing a itemHash attribute containing all the datums for that datasource. You can compare the datum handed to you against this. This is not a great solution since it could easily break and doesn't work for remote datums. I am working on a pull request that would pass the datasource the datum was from to the listen handler. It is relatively simple, but I don't know if it would be accepted. I am not quite done, but you can see it at work here.

http://jsfiddle.net/qWmf2/18/

I'll update this later when I have had more time to look at the ramifications of the changes I made.

jeffmax avatar Apr 19 '13 02:04 jeffmax

@jeffmax I like your work - yeah looking to use it on a remote source. I hope this gets the tick of approval. Thanks.

visualjazz-dporter avatar Apr 19 '13 02:04 visualjazz-dporter

Seems like similar issue as #196 There @jharding suggested using namespaced events to accomplish a similar result. Your idea seems more direct in terms of uniformly handling the data and using the dataset name as added information, whereas namespaced events is more elegant from the event listener perspective, since you can avoid using if's. But I guess is comes down to what is the more common use-case.

dannyc avatar Apr 21 '13 09:04 dannyc

I'm going to close this in favor of #196.

jharding avatar Apr 22 '13 00:04 jharding