Hybrid View

  1. #1
    Sencha User tomalex0's Avatar
    Join Date
    Apr 2009
    Location
    San Jose, CA
    Posts
    589
    Vote Rating
    16
    tomalex0 will become famous soon enough

      0  

    Default find Exact in extjs 2.3

    find Exact in extjs 2.3


    How could we find exact match of value in store

    i tried below but its not working properly
    Code:
    store.find('name','demo')

  2. #2
    Sencha User tomalex0's Avatar
    Join Date
    Apr 2009
    Location
    San Jose, CA
    Posts
    589
    Vote Rating
    16
    tomalex0 will become famous soon enough

      0  

    Default


    Its solved now

    Code:
    var val="^demo$"; 
    var newval=new RegExp(val);
    store.find('name',newval);

  3. #3
    Ext User
    Join Date
    Jul 2008
    Posts
    4
    Vote Rating
    0
    california is on a distinguished road

      0  

    Default


    Can't find the right if there exists special characters ( , ) , ?...

  4. #4
    Ext User
    Join Date
    Jul 2008
    Posts
    4
    Vote Rating
    0
    california is on a distinguished road

      0  

    Default


    Solution :
    Code:
    Ext.override(Ext.data.Store,{
        /**
         * Finds the index of the first matching record in this store by a specific property/value.
         * @param {String} property A property on your objects
         * @param {String/RegExp} value The value to match against
         * @param {Number} startIndex (optional) The index to start searching at
         * @return {Number} The matched index or -1
         */
        findExact: function(property, value, start){
            return this.data.findIndexBy(function(rec){
                return rec.get(property) === value;
            }, this, start);
        }
    });
    example: store.findExact("name","Finds the index (1)");
    Last edited by california; 18 May 2010 at 3:24 AM. Reason: edit

Thread Participants: 1