-
19 Apr 2010 9:17 AM #1
ComboBox Type Ahead, detect matching characters other than from the beginning
ComboBox Type Ahead, detect matching characters other than from the beginning
My ListStore contains full names (i.e. John Doe). I want type ahead to match not only on first name, but on last name as well. This is the behavior of GWT SuggestBox.
Is there a setter that I can call to enable this behavior? My code is:
Code:ComboBox<ModelData> combo = new ComboBox<ModelData>(); combo.setDisplayField("display"); combo.setId("id"); combo.setStore(listStore); combo.setTypeAhead(true); combo.setTriggerAction(ComboBox.TriggerAction.ALL);
-
20 Apr 2010 12:48 AM #2
You need to customize your Store. There is a simple change required in applyFilters method (change beginsWith to contains):
Code:public class CustomListStore<M extends ModelData> extends ListStore<M> { /** * Applies the current filters to the store. * * @param property * the optional active property */ @Override public void applyFilters(String property) { filterProperty = property; if (!filtersEnabled) { snapshot = all; } filtersEnabled = true; filtered = new ArrayList<M>(); for (M items : snapshot) { if ((filterBeginsWith != null) && (property != null)) { Object o = items.get(property); if (o != null) { if (!o.toString().toLowerCase().contains(filterBeginsWith.toLowerCase())) { continue; } } } if (!isFiltered(items, property)) { filtered.add(items); } } all = filtered; if (storeSorter != null) { applySort(false); } fireEvent(Filter, createStoreEvent()); } }
-
20 Apr 2010 12:26 PM #3
Thanks for the tip. However, this does not work as I would expect. For example if I have some names in my list "Dave Lastname", "George Anothername", "Pete Thirdname". If I type "a" and pause for a second "Dave Lastname" would get put into the combo box in a highlighted mode. If I start typing again the "a" that I had typed would disappear to be replaced by a D. I assume that I need to make an adjustment to my combo box to compensate for this. Any ideas?
-
13 May 2010 10:39 AM #4
The solution for this is:
Even without type ahead the list is filtered as I desire. I can't see the point of ever using setTypeAhead(true);Code:combo.setTypeAhead(false);
-
11 Oct 2011 1:28 PM #5
Would be nice to incorporate this as a feature
Would be nice to incorporate this as a feature
It would be better if this code were maintained by sencha or at least have the code be more OO - overriding applyFilters in this way means copying lots of implementation details (snapshot, filtersenabled, etc.) that could change and could break my code.
It would be nice to be able to override a simpler boolean typeAheadAccept() method or something like that
Copying and modifying the source code is always a dodgy operation and it would be nice if we could avoid it
-
16 Aug 2012 11:05 AM #6
Any movement on this?
Any movement on this?
We're at the point of needing this as a regular feature and I hate over-riding and copying source-code implementation into my over-ride.
What's the chance that this will become a standard feature?


Reply With Quote