ExtJs:在组合框中搜索/过滤 [英] 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"事件类型,以便过滤我添加的每个字母的结果.我怎样才能做到这一点?有什么想法吗?
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?
提前准备了很多坦克 :)
Tanks a lot in advance :)
希尔迪
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...
推荐答案
anyMatch: true
就是你所需要的.(就像在 SQL ... LIKE '%a%' 中一样)只要添加这个就可以完成.
anyMatch: true
is all you need. (like in SQL ... LIKE '%a%') as you asked can be done by simply add this.
示例:
Ext.create('Ext.form.ComboBox', {
name: 'name',
anyMatch: true,
allowBlank: true,
editable : true,
typeAhead: true,
transform: 'stateSelect',
forceSelection: true,
queryMode: 'local',
displayField: 'name',
valueField: 'id',
selectOnFocus: true,
triggerAction: 'all',
store: {
fields: ['id', 'name'],
proxy: {
type: 'ajax',
url: '/user'
},
autoLoad: true,
autoSync: true
}
})
这篇关于ExtJs:在组合框中搜索/过滤的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!