Results 1 to 5 of 5

Thread: Mixing proxy data + custom local data into a combobox store : is it possible ?

  1. #1

    Default Answered: Mixing proxy data + custom local data into a combobox store : is it possible ?

    Hi all,

    I'm trying to figure out how to have a combobox which values are a mix of :
    1. Values retrieved on a server via a proxy
    2. Custom local values

    My following code is :

    1. building a store via a proxy, all this via a dedicated function (that encapsulates specific params for the URL to be requested + start & limit params).

    2. trying to insert a custom data into this store, with no success at all...


    Here is the function that builds my store via a proxy.
    This function works as my combobox using the returned store displays the correct values :
    Code:
    function buildStore(viewname, start, limit)
    {
        url = HTTP_Root + '/' + viewname + "?ReadViewEntries&outputformat=JSON";
        
        var model = Ext.define('viewRow',
        {
            extend: 'Ext.data.Model',
            fields: [
                {name: 'position', mapping: '@position'},
                {name: 'unid', mapping: '@unid'},
                {name: 'c1', mapping: 'entrydata[0].text[0]'}
            ]        
        })
        
        var proxy = Ext.create('Ext.data.proxy.Ajax', {
            url: url,
            startParam: 'start',
            limitParam: 'count',
            reader: {
                type: 'json',
                root: 'viewentry',
                totalProperty: '@toplevelentries'            
            }
        });
    
    
        newStore = Ext.create('Ext.data.Store', { 
            proxy: proxy,
            model: model
        });
        
        var operation = Ext.create('Ext.data.Operation', {
            action: 'read',
            start: start,
            limit : limit
        });
        
        newStore.load(operation);
        return newStore;
    }
    Now, when I'm trying to be build manually some new data and insert it into the store, nothing happens.
    There are no error messages, but the console displays exactly the same store BEFORE and AFTER the insertion... What am I doing wrong ?

    Thanks for your help.

    Code:
        addressBookStore = buildStore('lookupResourcesByName', 1, 1000);
        var everybody = {
            position: '000',
            unid: '007',
            c1: 'James Bond'
        }
    
    
        console.log(addressBookStore);
        addressBookStore.insert(0, everybody);
        console.log(addressBookStore);

  2. If I read your code correctly it appears that you are kicking off an asynchronous store load and then inserting an item manually before the load has completed. When the load completes it will remove all previous items.

    You should just need to insert the extra item after the load has completed, possibly in a load event listener.

  3. #2
    Sencha Premium User evant's Avatar
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    19,254
    Answers
    759

    Default

    The object in the console reflects it's current state:

    Code:
    var o = {
        foo: 1
    };
    console.log(o);
    delete o.foo;
    o.bar = 2;
    console.log(o);
    Chances are the following is happening:
    1) You add a record to the store
    2) You load the remote data
    3) The store clears everything and loads the remote data
    Twitter - @evantrimboli
    Former Sencha framework engineer, available for consulting.
    As of 2017-09-22 I am not employed by Sencha, all subsequent posts are my own and do not represent Sencha in any way.

  4. #3

    Default Strange...

    Thank you for your reply.

    But in the case you mention, the object state should be the last evaluated state of the object (like in your example), which in my case is AFTER the "insert" method call.

    Anyway : is there a way to update the store state after the manual insertion of a new item, in order to use the "final" store in - for example - a combobox ?

  5. #4
    Sencha Premium Member skirtle's Avatar
    Join Date
    Oct 2010
    Location
    UK
    Posts
    3,791
    Answers
    585

    Default

    If I read your code correctly it appears that you are kicking off an asynchronous store load and then inserting an item manually before the load has completed. When the load completes it will remove all previous items.

    You should just need to insert the extra item after the load has completed, possibly in a load event listener.

  6. #5

    Default Right !

    +1 for you...
    As I'm running my server locally, I didn't think about the time to load data !

    Inserting my custom items in a load event solves all.
    Thank you very much.

Tags for this Thread

Posting Permissions

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