1. #1
    Ext JS Premium Member
    Join Date
    Nov 2010
    Posts
    14
    Vote Rating
    -1
    mniland is an unknown quantity at this point

      0  

    Default Matching IDs from loaded data to records in a store

    Matching IDs from loaded data to records in a store


    I don't know if this is working as intended, if I'm misunderstanding something, or it's a bug, so I'll start here.

    Let's say I have a store with two items:

    [{id:30, name:"Thirty"}, {id:3, name:"Three"}]

    It's attached to a combobox, and in order to list the items alphabetically, they're in the above order.

    I select "Three" and save it to a database, then later reload the form which loads my saved record from the database. The valueField on the combobox is id.

    What seems to be happening is that after loading the data, the record that will be selected and loaded into the combobox is based on the first match, not an exact match. In this example, {id:3} would come back from the database, and the combobox would load {id:30, name:"Thirty"} from the store - it appears to have matched the loaded ID to the first digit of the first ID in the store.

    Has anyone else seen this behavior?

  2. #2
    Ext JS Premium Member
    Join Date
    Nov 2010
    Posts
    14
    Vote Rating
    -1
    mniland is an unknown quantity at this point

      0  

    Default


    I solved this by overriding findRecord in my combobox UX.

    The default findRecord in ComboBox looks like this:
    Code:
        findRecord: function(field, value) {
            var ds  = this.store,
                idx = ds.find(field, value);
    
            if (idx !== -1) {
                return ds.getAt(idx);
            } else {
                return false;
            }
        },
    My minor modification:
    Code:
                findRecord: function(field, value) {
                    var ds  = this.store,
                        idx = ds.find(field, value, 0, false, false, true);
    
                    if (idx !== -1) {
                        return ds.getAt(idx);
                    } else {
                        return false;
                    }
                }
    For reference, the signature of Store.find:

    Code:
        find: function(property, value, start, anyMatch, caseSensitive, exactMatch)

Similar Threads

  1. Replies: 6
    Last Post: 1 Apr 2009, 8:12 AM
  2. calling two store synchronously and getting records when both of them loaded
    By emredagli in forum Ext 2.x: Help & Discussion
    Replies: 1
    Last Post: 6 Aug 2008, 6:55 AM
  3. [HELP] Updating Loaded Ext.data.Store
    By Phunky in forum Ext 2.x: Help & Discussion
    Replies: 2
    Last Post: 10 Dec 2007, 2:48 AM
  4. Function that is ran after data is loaded with Ext.data.store
    By djudjublondin in forum Ext 1.x: Help & Discussion
    Replies: 4
    Last Post: 31 Aug 2007, 6:33 AM
  5. Replies: 1
    Last Post: 29 Jun 2007, 12:40 AM