1. #1
    Ext User
    Join Date
    Dec 2008
    Posts
    74
    Vote Rating
    0
    Hemant Bob is on a distinguished road

      0  

    Default How to load the store from a form load xml response

    How to load the store from a form load xml response


    Hello All,

    I am having a form panel and I am loading xml data on the load event.
    This is working Ok. I am having a dataview in my page which expects a store and tpl. The issue is, I will get the data for this dataview store in the xml response of form load(So there are no two server calls). So, when I get the xml response for form load, I want to set the data for this dataview store, and used that in tpl.

    My xml is like this(Note this is the xml response on form load).

    Code:
    -- xml data which will be useful for other fields in form
    ---------
    -- Below is the data which I need to use to set dataview store for tpl.
    <TagFiles>
      <TagFile>
        <Id>0</Id> 
        <Tag>
          <Id>0</Id> 
          <TagText>kw1</TagText> 
        </Tag>
      </TagFile>
      <TagFile>
        <Id>1</Id> 
        <Tag>
          <Id>1</Id> 
          <TagText>kw3</TagText> 
        </Tag>
      </TagFile>
    ------
    ------
    </TagFiles>
    This is the form load action;
    Code:
            this.getForm().reader = new Ext.data.XmlReader({
                    record: '',
                    success: '@success'
                    },[
                    {name: 'id', mapping: 'Id'},
                     ...... Other elemtns 
                    {name: 'TagFiles'}, --> Here I need to do something to load records which will be use in dataview record.
            ]); 
    
            this.on("render",function(){
                this.getForm().load({url:"test.xml", waitMsg: "Loading..."});
            });
    I just want to set some records Array in the form load event for TagFiles, and set this as the data to the dataview store.

    This is my dataview,
    Code:
                    items: new Ext.DataView({
                        id: 'test-info-data-view',
                        store:   new Ext.data.SimpleStore({  
                                     fields: ['TagText'],        
                                     data: this.tagRecords --> This parameter I want to set in form load event which will used in this dataview store          
                       }); 
                        tpl: new Ext.XTemplate(          
                                '<tpl for=".">',
                                '<div>',
                                    '<table width="100%">',
                                        '<tr>',
                                               '<td>{TagText}</td>',            
                                           '</tr>',
                                       '</table><br/>',
                                '</div></tpl>'             
                            )
                    })
    Am I clear to you all?

    Thanks and Keenly waiting for your replys..

  2. #2
    Sencha - Community Support Team Condor's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    24,246
    Vote Rating
    91
    Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of

      0  

    Default


    Configure your dataview store for reading the XML:
    Code:
    items: new Ext.DataView({
    	id: 'test-info-data-view',
    	store: new Ext.data.Store({
    		reader: new Ext.data.XmlReader({
    			record: 'TagFile',
    			fields: ['TagText']
    		})
    	}),
    	...
    });
    and load the store after the form is loaded:
    Code:
    form.on('actioncomplete', function(form, action){
    	if(action.type == 'load'){
    		Ext.getCmp('test-info-data-view').loadData(form.reader.xmlData);
    	}
    });
    (the form reader doesn't need to have a TagFiles field)

  3. #3
    Ext User
    Join Date
    Dec 2008
    Posts
    74
    Vote Rating
    0
    Hemant Bob is on a distinguished road

      0  

    Default


    Thanks Condor!!,
    That's Great!!, That worked perfectly for me
    With a little modification

    Code:
    Ext.getCmp('test-info-data-view').store.loadData(this.getForm().reader.xmlData);

Thread Participants: 1