PDA

View Full Version : ComboBox autocomplete with local mode - substring search instead of prefix match



nightwatch
4 Jul 2012, 3:42 AM
Hi, I have a combobox configured for autocompletion in queryMode: "local":


editor: {xtype: 'combobox', store: dataSrcSt, valueField: 'Id', displayField: 'Description', allowBlank: false, queryMode: 'local', typeAhead: true, minChars: 2}

And the autocomplete seems to work - it matches a correct entry if a prefix of the display value is entered. But what should I do to filter the entries by matching a substring anywhere in the display value ( 'displayValue like *typedText*', not 'like typedText*')

ExtJS 4.1

Thanks
RG

Romick
4 Jul 2012, 6:24 AM
You can try this:


Ext.onReady(function() {

var simpleCombo = Ext.create('Ext.form.field.ComboBox', {
fieldLabel: 'Select a single state',
displayField: 'name',
valueField: 'abbr',
width: 320,
labelWidth: 130,
queryMode: 'local',
typeAhead: true,
minChars: 2,
name: 'agentDownline',
store: new Ext.data.SimpleStore({
fields: ['abbr', 'name', 'slogan'],
data: [
['VA', 'Virginia', 'Mother of States'],
['WA', 'Washington', 'Green Tree State'],
['WV', 'West Virginia', 'Mountain State'],
['WI', 'Wisconsin', 'America\'s Dairyland'],
['WY', 'Wyoming', 'Like No Place on Earth']
]
}),
listeners: {
buffer: 50,
change: function() {
var store = this.store;
//store.suspendEvents();
store.clearFilter();
//store.resumeEvents();
store.filter({
property: 'name',
anyMatch: true,
value : this.getValue()
});
}
}
});

Ext.create("Ext.Window", {
items: simpleCombo
}).show();

Is that what you are looking for?

nightwatch
6 Jul 2012, 4:43 AM
Yes, that's the solution. Thanks!

kitteh
11 Jul 2013, 11:26 PM
Thanks from me too, it helped me alot!!!

jdflores
23 Jul 2013, 2:53 PM
The combobox has an extra property as of 4.1.3, it's called 'enableRegEx'. If the mode is local it will do the matching without having to listen for a change in this field.

G10
1 Oct 2014, 6:55 AM
The combobox has an extra property as of 4.1.3, it's called 'enableRegEx'. If the mode is local it will do the matching without having to listen for a change in this field.


I set enableRegEx to true and autocomplete works fine but it does not filter the combobox content. Is there any way to fix this?