Extjs combobox 模糊搜尋
Extjs3: https://www.sencha.com/forum/showthread.php?21719-Contains-instead-of-Starts-with-in-ComboBox-autocomplete
(用於通訊錄系統)
加入代碼:
- Ext.override(Ext.form.ComboBox, {
- doQuery : function(q, forceAll){
- if(q === undefined || q === null){
- q = ’’;
- }
- var qe = {
- query: q,
- forceAll: forceAll,
- combo: this,
- cancel:false
- };
- if(this.fireEvent(’beforequery’, qe)===false || qe.cancel){
- return false;
- }
- q = qe.query;
- forceAll = qe.forceAll;
- if(forceAll === true || (q.length >= this.minChars)){
- if(this.lastQuery !== q){
- this.lastQuery = q;
- if(this.mode == ’local’){
- this.selectedIndex = -1;
- if(forceAll){
- this.store.clearFilter();
- }else{
- this.anyMatch = this.anyMatch === undefined? false : this.anyMatch;
- this.caseSensitive = this.caseSensitive === undefined? false : this.caseSensitive;
- this.store.filter(this.displayField, q, this.anyMatch, this.caseSensitive);
- }
- this.onLoad();
- }else{
- this.store.baseParams[this.queryParam] = q;
- this.store.load({
- params: this.getParams(q)
- });
- this.expand();
- }
- }else{
- this.selectedIndex = -1;
- this.onLoad();
- }
- }
- }
- });
並於 combobox config加入
’anyMatch: true’
’caseSensitive: true’ //選用
Extjs4: http://atechiediary.blogspot.tw/2013/06/first-page-extjs-containslike-search-in.html
(未實際套用過)
1.於configuration加入
typeAhead: true
editable: true
2.加入listeners
- listeners: {
- beforequery: function (record) {
- record.query = new RegExp(record.query, ’i’);
- record.forceAll = true;
- }
- }