ExtJs: Search / Filter within a ComboBox

后端 未结 8 1327
甜味超标
甜味超标 2021-01-05 15:05

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 = [[\         


        
相关标签:
8条回答
  • 2021-01-05 15:49

    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; 
         }
     }
    
    0 讨论(0)
  • 2021-01-05 15:50

    just remove that lister and override the doQuery method as follows

    if(combo!=null){
        combo.doQuery = function(q, forceAll){
      q = Ext.isEmpty(q) ? '' : 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.store.filter(this.displayField, q, true,false); // supply the anyMatch option
                      }
                      this.onLoad();
                  }else{
                      this.store.baseParams[this.queryParam] = q;
                      this.store.load({
                          params: this.getParams(q)
                      });
                      this.expand();
                  }
              }else{
                  this.selectedIndex = -1;
                  this.onLoad();
              }
          }
      };
    }
    
    0 讨论(0)
提交回复
热议问题