Results 1 to 6 of 6

Thread: How to refresh a store's url and a Grid, Please ? I need your help...

  1. #1

    Exclamation How to refresh a store's url and a Grid, Please ? I need your help...

    Hi,
    In this example, I load a grid with an xml file (Spring.xml) which have his name in an other xml file (conf.xml).
    It works. So I load too a combo box with my conf.xml file which propose all name's file in the conf.xml (Spring.xml and Summer.xml). It works too.
    But when I select Summer.xml in my combo box, my Grid isn't refresh with Summer.xml instead Spring.xml...
    Please, help me !

    I give you all so that you can test and help me.
    There is 5 files :

    1. conf.xml
    2. Spring.xml
    3. Summer.xml
    4. index.xml
    5. myTst.xml


    Here is my conf.xml :
    Code:
    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <Params>
        <GridFiles>
            <GridFile>
                <IDFile>1</IDFile>
                <NameFile>Spring.xml</NameFile>
            </GridFile>    
            <GridFile>
                <IDFile>2</IDFile>
                <NameFile>Summer.xml</NameFile>
            </GridFile>                            
        </GridFiles>
    </Params>
    Here is Spring.xml :
    Code:
    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <Root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
        <Row>
            <ProductID>1</ProductID>
            <ProductName>Chai</ProductName>
            <CategoryName>Beverages</CategoryName>
            <Sales>1940704</Sales>
        </Row>
        <Row>
            <ProductID>2</ProductID>
            <ProductName>Chang</ProductName>
            <CategoryName>Beverages</CategoryName>
            <Sales>264307</Sales>
        </Row>
        <Row>
            <ProductID>3</ProductID>
            <ProductName>Aniseed Syrup</ProductName>
            <CategoryName>Condiments</CategoryName>
            <Sales>322988</Sales>
        </Row>
        <Row>
            <ProductID>4</ProductID>
            <ProductName>Chef Antons Cajun Seasoning</ProductName>
            <CategoryName>Condiments</CategoryName>
            <Sales>2974243</Sales>
        </Row>
        <Row>
            <ProductID>5</ProductID>
            <ProductName>Chef Antons Gumbo Mix</ProductName>
            <CategoryName>Condiments</CategoryName>
            <Sales>1833049</Sales>
        </Row>
    </Root>
    Here is Summer.xml (only Sales change compared to Spring.xml...) :
    Code:
    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <Root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
        <Row>
            <ProductID>1</ProductID>
            <ProductName>Chai</ProductName>
            <CategoryName>Beverages</CategoryName>
            <Sales>1452194</Sales>
        </Row>
        <Row>
            <ProductID>2</ProductID>
            <ProductName>Chang</ProductName>
            <CategoryName>Beverages</CategoryName>
            <Sales>669923</Sales>
        </Row>
        <Row>
            <ProductID>3</ProductID>
            <ProductName>Aniseed Syrup</ProductName>
            <CategoryName>Condiments</CategoryName>
            <Sales>2162087</Sales>
        </Row>
        <Row>
            <ProductID>4</ProductID>
            <ProductName>Chef Antons Cajun Seasoning</ProductName>
            <CategoryName>Condiments</CategoryName>
            <Sales>1639312</Sales>
        </Row>
        <Row>
            <ProductID>5</ProductID>
            <ProductName>Chef Antons Gumbo Mix</ProductName>
            <CategoryName>Condiments</CategoryName>
            <Sales>1801412</Sales>
        </Row>
    </Root>
    Here is my index.html :
    HTML Code:
    <html>
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
            <title>Asynchronous Test 03</title>
            <!-- Common Styles ExtJS -->
            <link rel="stylesheet" type="text/css" href="../extJS/resources/css/ext-all.css" />
    
            <!-- GC -->
            <!-- LIBS -->
            <script type="text/javascript" src="../extJS/adapter/ext/ext-base.js"></script>
            <!-- ENDLIBS -->
    
            <!-- Common JavaScript ExtJS -->        
            <script type="text/javascript" src="../extJS/ext-all.js"></script>    
            
            <!-- JavaScript for the Mock-Up --> 
            <script type="text/javascript" src="myTst.js"></script>
            
        </head>
        
        <body>
    
        </body>
        
    </html>
    And the more important, the myTst.js file :
    Code:
    /*!
     * Ext JS Library 3.2.1
     * Copyright(c) 2006-2010 Ext JS, Inc.
     * [email protected]
     * http://www.extjs.com/license
     */
    
    Ext.onReady(function(){
        Ext.QuickTips.init();
    
        var first = true;
        
        // My Reader and my Store
        var recordConfReader = new Ext.data.XmlReader({
            record: 'GridFile',
            id: 'IDFile',
            fields: [
            {name: 'IDFile', type: 'string'},
            {name: 'NameFile', type: 'string'}
            ]});
            
        var storeConf = new Ext.data.Store({
            url: 'conf.xml',
            reader: recordConfReader
        });
        
        storeConf.load();
        
        // ASYNCHRONOUS SECTION FOR STORECONF
        //===================================
        storeConf.on("load", function(s,rs) {
            var myGridXmlFile = ''
            myGridXmlFile = storeConf.getAt(storeConf.find('IDFile','1')).get('NameFile');
            // Data Store for the Grid
                var storeMain = new Ext.data.Store({
                    url: myGridXmlFile,
                    
                    reader: new Ext.data.XmlReader({
                        record: 'Row',
                        id: 'ProductID',
                        fields: [
                        {name: 'ProductName', type: 'string'},
                        {name: 'CategoryName', type: 'string'},
                        {name: 'Sales', type: 'float'}
                        ]
                        })
                    ,listeners:{
                        load:{fn:function(){
                            storeMain.url = myGridXmlFile;
                            //mainGrid.refresh(); //No refresh method for a GridPanel object ??? Try reconfigure metho below...
                            Ext.MessageBox.alert('storeMain URL : ', storeMain.url);
                        }}}
                });
            storeMain.load();    
    
            // Main Grid
            var mainGridColModel = new Ext.grid.ColumnModel({
                columns: [
                    {header: "Product Name", width: 180, dataIndex: 'ProductName', sortable: true},
                    {header: "Category Name", width: 100, dataIndex: 'CategoryName', sortable: true},            
                    {header: "Sales", width: 80, dataIndex: 'Sales', sortable: true, renderer: 'usMoney'}
                ]
            });        
            var mainGrid = new Ext.grid.GridPanel({
                store: storeMain,
                region:'center',
                colModel: mainGridColModel
                ,width:950
                ,height:300
                ,id:'main-grid'
                ,triggerAction:'all'
                ,mode:'local'
                ,lastQuery:''
            });
                    
            // Combobox XML's Files    
            var valueComboXmlFile = '';
            var txtComboXmlFile = '';
            
            var comboXmlFile = new Ext.form.ComboBox({
                 id:'combo-xmlfiles'
                ,region: 'north'         
                ,fieldLabel:'Xml Files'
                ,displayField:'NameFile'
                ,valueField:'IDFile'
                ,store: storeConf
                ,emptyText:'Select another Xml File...'
                ,triggerAction:'all'
                ,mode:'local'
                ,lastQuery:''
                ,listeners:{
                select:{fn:function(combo, value)
                {                            
                    // Test retrieval Value and Text Selected
                    //----------------------------------------                    
                    valueComboXmlFile = combo.getValue();
                    txtComboXmlFile = storeConf.getAt(storeConf.find('IDFile',valueComboXmlFile)).get('NameFile');
                    //Ext.MessageBox.alert('Tests', 'txt : '+txtComboXmlFile+' ; value : '+valueComboXmlFile);
                    
                    //Reload with xml file selected
                    //------------------------------
                    myGridXmlFile = txtComboXmlFile;
                    storeMain.reload();
                }    
                }}
            });    
    
            
            // Panel and Render    
            var panel = new Ext.Panel({
                id:'my-panel',
                frame:true,
                width:535,
                autoHeight:true,
                collapsible:true,
                layout:'fit',
                title:'Tests load and reload grid from conf.xml',
                items: [comboXmlFile,mainGrid]
            });
            
            panel.render(document.body);                
                
        }); // end of storeConf asynchro
    });
    So, in the javascript file, after the part where i get the xml file selected (in red above), how can i refresh url of my store and refreh my Grid ? I try something (in blue above) but it dont' work...

    Many thanks for your help,

  2. #2

    Default

    Please, i need help...

  3. #3
    Sencha User cyclops's Avatar
    Join Date
    Dec 2009
    Posts
    15

    Default

    Have you tried to change storeMain.url directly in the "red" part of your code?

  4. #4
    Sencha User Condor's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    24,246

    Default

    Code:
    store.proxy.setUrl(newUrl);
    store.load();
    ps. getById() is a lot faster than find():
    Code:
    myGridXmlFile = storeConf.getById('1').get('NameFile');

  5. #5

    Default

    Many thanks cyclops and Condor, i'll try that

  6. #6

    Default

    Great! I've replace that :

    Code:
                    myGridXmlFile = txtComboXmlFile;
                    storeMain.reload();
    by :
    Code:
                    myGridXmlFile = txtComboXmlFile;
                    storeMain.proxy.setUrl(myGridXmlFile);
                    storeMain.load();
    And it works!

    Many thanks for that... and for the tip about getById

Similar Threads

  1. Replies: 0
    Last Post: 21 Aug 2009, 1:58 PM
  2. Refresh Grid after store update
    By hartwigpl in forum Ext GWT: Help & Discussion (1.x)
    Replies: 0
    Last Post: 27 Feb 2009, 1:13 PM
  3. How to refresh tabs url?
    By michal in forum Ext 2.x: Help & Discussion
    Replies: 1
    Last Post: 5 Jun 2008, 4:31 AM
  4. loading data into a store does not cause the associated grid to refresh
    By bmf1972 in forum Ext 2.x: Help & Discussion
    Replies: 3
    Last Post: 21 Apr 2008, 11:04 PM
  5. Store: grid doesn't follow new proxy url
    By Liese in forum Ext 1.x: Help & Discussion
    Replies: 3
    Last Post: 21 Sep 2007, 3:46 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
  •