ExtJs:在ComboBox中搜索/过滤 [英] ExtJs: Search / Filter within a ComboBox
问题描述
我在ExtJs 2.3中遇到以下问题/问题:
I've the following problem / question in ExtJs 2.3:
我想在组合框中进行搜索。
我给你一个例子:
I'd like to do a search within a combobox. I'll give you an example:
Ext.comboData.names = [['Peter', 'Paul', 'Amanda']];
var store = new Ext.data.SimpleStore({
fields: ['name'],
data: Ext.comboData.names
});
var combo = new Ext.form.ComboBox({
name: '...',
id: '...',
store: store,
displayField: 'name',
typeAhead: true,
mode: 'local',
forceSelection: false,
triggerAction: 'all',
emptyText: '-',
selectOnFocus: true,
applyTo: '...',
hiddenName: '...',
valueField: 'name'
enableKeyEvents: true,
lastQuery: '',
listeners: {
'keyup': function() {
this.store.filter('name', this.getRawValue(), true, false);
}
}
});
当我输入'a'时,只有'Paul'和'Amanda'在下拉菜单。所以换句话说,我正在寻找一个解决方案来过滤数据不仅通过条目的第一个字母,但也许通过使用像正则表达式(?)(像SQL ... LIKE'%a%') ...我还需要类型的onKeyDown - 事件为我的comboBox为了过滤我添加的每一个字母的结果。
我如何做到这一点?
When I would type in an 'a', there only should be 'Paul' and 'Amanda' in the "dropdown". So in other words I'm looking for a solution to filter the data not only by the entries' first letter, but maybe by using something like a regular expression (?) (like in SQL ... LIKE '%a%')...I also would need type of "onKeyDown"-event for my comboBox in order to filter the results on every single letter I add. How can I do that? Any ideas?
坦克:
Schildi
PS:不幸的是,我必须使用我当前版本的ExtJs(2.3),所以如果有一个解决方案,我的问题只是在以后的版本,我将不得不寻找另一种方法...
PS: Unfortunately I have to use my current version of ExtJs (2.3), so if there's a solution for my problem just in later versions, I would have to look for an other way...
推荐答案
我知道这是一个老问题,但这里最好的答案建议覆盖 doQuery
。应该避免覆盖私有方法,尤其是如果你要升级。相反,只需添加 beforequery
监听器以阻止 doQuery
清除过滤器。
I know this is an old question, but the best answers here recommend overriding doQuery
. Overriding private methods should be avoided especially if you are ever going to upgrade. Instead, just add a beforequery
listener to prevent doQuery
from clearing the filter.
listeners: {
'keyup': function() {
this.store.filter('name', this.getRawValue(), true, false);
},
'beforequery': function(queryEvent) {
queryEvent.combo.onLoad();
// prevent doQuery from firing and clearing out my filter.
return false;
}
}
这篇关于ExtJs:在ComboBox中搜索/过滤的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!