Results 1 to 3 of 3

Thread: Adding an additional datastore when using single-file grid definition+data

  1. #1
    Sencha User
    Join Date
    Dec 2009
    Posts
    5

    Default Adding an additional datastore when using single-file grid definition+data

    Hi Everyone,

    I am still getting acquainted with a lot in Ext but moving along so far... I have been using mostly the following example to load the columns and data from a single file - http://www.sencha.com/forum/showthre...ogrid-solution

    I think it is most useful because that way I can taylor the view from my script, and send the appropriate columns and data... one question that I have is the following, would it be possible to add an additional datastore with this setup to be able to use cross-lookups with special renderers?

    I would like to have something like this:

    Code:
    {"success":true,
     "metaData": { 
     "columns": [
       {"text": "ID","dataIndex": 'id',
       {"text": "user_id","dataIndex": "user_id", renderer: function(value){
    ///////my code to lookup data from another store by id...UsersStore.getById(value);
    }}}
     ] 
     },
    "data":[
        { "id": 1, "user_id":123    },
        { "id": 2, "user_id":456    }
    ],
    "users":[
        { "id": 123, "name":"rob"    },
        { "id": 456, "name":"john"    }
    ]}
    obviously my current grid code must now include this new "users" array/json object...

    Code:
    Ext.require(['Ext.data.*', 'Ext.grid.*']);
    
    Ext.define('Order', {
        extend: 'Ext.data.Model',
        fields: []
    });
    
    Ext.onReady(function(){
        var store = new Ext.data.Store({
            model: "Order"
        });
        
        
        var store = Ext.create('Ext.data.JsonStore', {
            model: 'Order',
            proxy: {
                type: 'rest',
                url: 'viewapi2.php',
                reader: {
                    type: 'json',
                    root: 'data'
                }
            }
        });  
        store.load({
            callback: function() {
                var columns=[];
                var data=store.getProxy().getReader().rawData;
                if (data.metaData) {
                     columns = data.metaData.columns;                 
                }
                var grid = Ext.create('Ext.grid.Panel', {
                    id:'usergrid',
                    renderTo: document.body, 
                    width: 400,
                    height: 300,
                    frame: true,
                    title: 'Users',
                    store: new Ext.data.Store({
                        model:"Order"
                    }),
                    iconCls: 'icon-user',
                    columns: columns
                });    
                 var jsonData=data.data;
                 var i=0;
                 for(i=0;i<jsonData.length;i++){
                       Ext.getCmp('usergrid').getStore().add(jsonData[i]);
                 } 
                }
        });
        store.load();    
    });
    Thanks a lot for any help

  2. #2
    Sencha Premium User mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    40,379
    Answers
    3997

    Default

    You could just merge the objects together in your store load callback.
    Mitchell Simoens @LikelyMitch

    Check out my GitHub:
    https://github.com/mitchellsimoens

    Posts are my own, not any current, past or future employer's.

  3. #3
    Sencha User
    Join Date
    Dec 2009
    Posts
    5

    Default

    Hello Mitchell,

    Thank you for trying to help. Nonetheless, as a newbie, I will need a bit more to get by...

    I tried setting a variable in the callback function previously, but that wasnt even visible from the renderer callback, so I dont think it would help me...

    Basically I want to utilize multiple datastores to do lookups on semi-static data without the need of doing the lookup in my application. Also, the store can also be used to populate form option values, etc...

Posting Permissions

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