Results 1 to 3 of 3

Thread: Adding a single record to an Array Store after its already been loaded

  1. #1
    Sencha User
    Join Date
    Jun 2009
    Posts
    419

    Default Adding a single record to an Array Store after its already been loaded

    Hi,

    I have an Array Store which populates with data from the server when my page loads.

    I then have a timed update routine which just polls the server for new data which returns only affected records in the results coming back. If I have a new record returned thats not already present in the store, should it just be a case of using the loadData method to add the new record it into my store?

    Sample Code:

    Code:
    //Page loads, setup my store
    store = new Ext.data.ArrayStore({
    
                fields: ['rowNo','untID','untName',other fields.....],
                idIndex: 1,
                sortInfo: {
                    field    : 'untName',
                    direction: 'ASC'
                }
            });
            
    
    //Grab initial set of data and populate store        
    store.loadData(_sesData.CurrentGridArray);
    
    //Timed Update Routine, polls server for any affected\new rows...
    
    PushCurrentGridUpdateEvent: function (sender, args) {
        if (args.CurrentGridArray)
        {
            var noOfUpdates = args.CurrentGridArray.length;
            for(var i=0; i<noOfUpdates; i++) {
                //Attempt to retrieve store item by id value
                storeItem = dataview.store.getById(args.CurrentGridArray[i][1]);
                if(storeItem) {
                    //Update data fields for store item....
                    storeItem.data.mapIconHTML=args.CurrentGridArray[i][2];
                    //Update rest of fields...
                }
                else {
                    //If storeItem is not found then we have a new record to add...
                
                    //NOTE: The true param ensures we append any new currentGridArray items to existing store cache
                    //rather than the default behaviour of replacing the items in the cache.
                    
                    dataview.store.loadData(args.CurrentGridArray[i],true);
                }
                
            }
                
        }
    
    }

  2. #2
    Sencha User
    Join Date
    Dec 2009
    Posts
    425

    Default

    You can add a record to a store using store.add(arr)
    where arr is an array of Record objects created as...
    Code:
    var rt = Ext.data.Record.create([
    {name: 'fullname'},
    {name: 'first'}
    ]);

  3. #3
    Sencha User
    Join Date
    Jun 2009
    Location
    Colorado
    Posts
    51

    Default

    Also check out the "append" option of the loadData method on the store.

Similar Threads

  1. Change the array loaded in the store
    By emmy mathew in forum Ext 3.x: Help & Discussion
    Replies: 1
    Last Post: 18 Jul 2010, 10:51 AM
  2. Reloading a single Record in a store
    By toddgeist in forum Ext 3.x: Help & Discussion
    Replies: 2
    Last Post: 27 Jun 2010, 9:52 AM
  3. Any way to updated a single record in store?
    By dbassett74 in forum Ext 3.x: Help & Discussion
    Replies: 2
    Last Post: 8 Sep 2009, 6:31 AM
  4. Adding a record to a store that is auto loaded
    By oshannon in forum Ext 2.x: Help & Discussion
    Replies: 4
    Last Post: 28 Jul 2009, 7:27 AM
  5. Replies: 6
    Last Post: 1 Apr 2009, 8:12 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •