1. #1
    Sencha User
    Join Date
    Nov 2009
    Location
    Chapecó, SC, Brazil
    Posts
    5
    Vote Rating
    0
    Rudiney is on a distinguished road

      0  

    Question Answered: Local combobox with any match filter.

    Answered: Local combobox with any match filter.


    Hello guys,

    Im using ExtJs 4.0.7 and i want to know if there is a way to filter a combobox with local data, with not only the beginnig string, but filtering any match values???

    In a example:
    Code:
    // local store
    var states = Ext.create('Ext.data.Store', {
      fields: ['abbr', 'name'],
      data : [
        {"abbr":"AL", "name":"Alabama"},
        {"abbr":"AK", "name":"Alaska"},
        {"abbr":"AZ", "name":"Arizona"}
      ]
    });
    
    Ext.create('Ext.form.ComboBox', {
      store: states,
      queryMode: 'local',
      displayField: 'name',
      valueField: 'abbr'
    });
    So when user type 'ask', to find 'Alaska' as an option...

    Can you help me???

    I have search forum for existing post, but got nothing for 4.x version. I found this post but doesnt help me....

    Thanks all.
    --
    Rudiney Altair Franceschi
    Web Developer

  2. The easiest way it probably to hack it into the store instead:

    Code:
    var store = Ext.create('Ext.data.Store', {
        ...
        filter: function(filters, value) {
            Ext.data.Store.prototype.filter.apply(this, [
                filters,
                value ? new RegExp(Ext.String.escapeRegex(value), 'i') : value
            ]);
        }
    });
    Alternatively, you could override doQuery:

    Code:
    Ext.create('Ext.form.field.ComboBox', {
        ...
        doQuery: function(queryString, forceAll) {
            this.expand();
            this.store.clearFilter(!forceAll);
    
            if (!forceAll) {
                this.store.filter(this.displayField, new RegExp(Ext.String.escapeRegex(queryString), 'i'));
            }
        }
    });
    Both work but both are pretty hacky.

  3. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    36,795
    Answers
    3466
    Vote Rating
    834
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    doQuery within combobox doesn't really do smart filtering but you can do it yourself.

    I would setup a keydown listener on the combobox and then do your filter there.
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

  4. #3
    Sencha User
    Join Date
    Nov 2009
    Location
    Chapecó, SC, Brazil
    Posts
    5
    Vote Rating
    0
    Rudiney is on a distinguished road

      0  

    Default


    Wow thanks for the quick answer!

    hmm, i have done some try with keydown listeners, but i think ive done something wrong....

    my try....
    Code:
    //using the same local store.....
    Ext.create('Ext.form.ComboBox', { 
      store: states, 
      queryMode: 'local',
      displayField: 'name', 
      valueField: 'abbr', 
      enableKeyEvents:true,  listeners: {
        keydown: function(){
          this.store.filter('name',/this.getRawValue()/);
        }
      }
    });
    Is this correct???
    --
    Rudiney Altair Franceschi
    Web Developer

  5. #4
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    36,795
    Answers
    3466
    Vote Rating
    834
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    You will need to use RegEx as the value.
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

  6. #5
    Sencha User
    Join Date
    Nov 2009
    Location
    Chapecó, SC, Brazil
    Posts
    5
    Vote Rating
    0
    Rudiney is on a distinguished road

      0  

    Default


    i have tested in javascript console using just .filter('name',/ask/) and got 'Alask' just how i need...

    Code:
    states = Ext.create('Ext.data.Store', {
      fields: ['abbr', 'name'],
      data : [
      {"abbr":"AL", "name":"Alabama"},
      {"abbr":"AK", "name":"Alaska"},
      {"abbr":"AZ", "name":"Arizona"}
      ]
    });
    
    //filtering with /rawValue/
    states.filter('name',/ask/);
    
    // alaska found!
    console.dir(states.data.items)
    Now i just need to show this filter result as combobox's options.....



    Thanks....
    --
    Rudiney Altair Franceschi
    Web Developer

  7. #6
    Sencha User
    Join Date
    Nov 2009
    Location
    Chapecó, SC, Brazil
    Posts
    5
    Vote Rating
    0
    Rudiney is on a distinguished road

      0  

    Default


    So... i know how to do a custom filter in combobox's store,

    how can i put these results as combobox's options????
    --
    Rudiney Altair Franceschi
    Web Developer

  8. #7
    Sencha Premium Member skirtle's Avatar
    Join Date
    Oct 2010
    Location
    UK
    Posts
    3,585
    Answers
    540
    Vote Rating
    319
    skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future

      2  

    Default


    The easiest way it probably to hack it into the store instead:

    Code:
    var store = Ext.create('Ext.data.Store', {
        ...
        filter: function(filters, value) {
            Ext.data.Store.prototype.filter.apply(this, [
                filters,
                value ? new RegExp(Ext.String.escapeRegex(value), 'i') : value
            ]);
        }
    });
    Alternatively, you could override doQuery:

    Code:
    Ext.create('Ext.form.field.ComboBox', {
        ...
        doQuery: function(queryString, forceAll) {
            this.expand();
            this.store.clearFilter(!forceAll);
    
            if (!forceAll) {
                this.store.filter(this.displayField, new RegExp(Ext.String.escapeRegex(queryString), 'i'));
            }
        }
    });
    Both work but both are pretty hacky.

  9. #8
    Sencha User
    Join Date
    Nov 2009
    Location
    Chapecó, SC, Brazil
    Posts
    5
    Vote Rating
    0
    Rudiney is on a distinguished road

      0  

    Default


    Thanks you! it works just fine!
    Thanks so much.
    --
    Rudiney Altair Franceschi
    Web Developer

  10. #9
    Sencha User
    Join Date
    Oct 2011
    Location
    Ukraine
    Posts
    154
    Answers
    11
    Vote Rating
    6
    Romick is on a distinguished road

      0  

    Default Filter

    Filter


    PHP Code:
      filter: function(fieldnewValue) {
        
    store.filter({
          
    property'name',
          
    anyMatchtrue,
          
    value   newValue
        
    });
      }, 

Turkiyenin en sevilen filmlerinin yer aldigi xnxx internet sitemiz olan ve porn sex tarzi bir site olan mobil porno izle sitemiz gercekten dillere destan bir durumda herkesin sevdigi bir site olarak tarihe gececege benziyor. Sitenin en belirgin ozelliklerinden birisi de Turkiyede gercekten kaliteli ve muntazam, duzenli porno izle siteleri olmamasidir. Bu yuzden iste. Ayrica en net goruntu kalitesine sahip adresinde yayinlanmaktadir. Mesela diğer sitelerimizden bahsedecek olursak, en iyi hd porno video arşivine sahip bir siteyiz. "The Best anal porn videos and slut anus, big asses movies set..." hd porno faketaxi