We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 38954
    • 24 Posts
    Finally i stock with extJs.
    What i do here is create FormPanel with some fields, which i populate on success ajax request.
    It works fine except i want also put some data in LocalGrid, on success, it where i stock.
    I load some default data in grid panel, just for check, what i want is totally renew all data with new store data.

    Orders.panel.Info = function(config) {
        
        config = config || {};
        Ext.apply(config,{
            border: false
            ,baseCls: 'modx-formpanel'
            ,items: [{
                html: '<h2>'+_('orders.management')+'</h2>'
                ,border: false
                ,cls: 'modx-page-header'
            },{
                xtype: 'modx-tabs'
                ,bodyStyle: 'padding: 10px'
                ,defaults: { border: false ,autoHeight: true }
                ,border: true
                ,items: [{
                    title: 'Order Description number ' + MODx.request.id
                    ,defaults: { autoHeight: true }
                    ,items: [{
                        html: '<p>'+'In this page you can see full info about your order.'+'</p>
    '
                        ,border: false
                    },{
                    	xtype: 'compositefield'
          //        	,labelWidth: 400
                    	,items: [{
                    		xtype: 'displayfield'
                    		,value: 'Name'
                   			,width: 330
                    	},{
                    		xtype: 'displayfield'
                    		,value: 'Lastname'
           //         		,width: 120
                    	}]
                    },{
                    	xtype: 'compositefield'
                    	,items: [{
                    		name: 'lblFirstName'
                    		,xtype: 'textfield'
                    		,value: ''
                    		
                    	},{
                    		name: 'lblLastName'
                    		,xtype: 'textfield'
                    		,value: ''
                    	}]
                    },{
                    	xtype: 'compositefield'
                    	
          //        	,labelWidth: 400
                    	,items: [{
                    		xtype: 'displayfield'
                    		,value: 'Middle Name'
                   			,width: 330
                    	},{
                    		xtype: 'displayfield'
                    		,value: 'Age'
           //         		,width: 120
                    	}]
                    },{
                    	xtype: 'compositefield'
                    	,items: [{
                    		name: 'lblMiddleName'
                    		,xtype: 'textfield'
                    		,value: ''
                    	},{
                    		name: 'lblAge'
                    		,xtype: 'textfield'
                    		,value: ''
                    	}]
                    },{
                    	xtype: 'compositefield'
          //        	,labelWidth: 400
                    	,items: [{
                    		xtype: 'displayfield'
                    		,value: 'Phone'
                   			,width: 330
                    	},{
                    		xtype: 'displayfield'
                    		,value: 'E-mail'
           //         		,width: 120
                    	}]
                    },{
                    	xtype: 'compositefield'
                    	,items: [{
                    		name: 'lblPhone'
                    		,xtype: 'textfield'
                    		,value: ''
                    	},{
                    		name: 'lblEmail'
                    		,xtype: 'textfield'
                    		,value: ''
                    	}]
                    },{
                    	xtype: 'compositefield'
          //        	,labelWidth: 400
                    	,items: [{
                    		xtype: 'displayfield'
                    		,value: 'Marriage Date'
                   			,width: 330
                    	},{
                    		xtype: 'displayfield'
                    		,value: 'Marriage Place'
           //         		,width: 120
                    	}]
                    },{
                    	xtype: 'compositefield'
                    	,items: [{
                    		name: 'lblPartyDate'
                    		,xtype: 'textfield'
                    		,value: ''
                    	},{
                    		name: 'lblMesto'
                    		,xtype: 'textfield'
                    		,value: ''
                    	}]
                    },{
                    	xtype: 'compositefield'
          //        	,labelWidth: 400
                    	,items: [{
                    		xtype: 'displayfield'
                    		,value: 'Guest'
                   			,width: 330
                    	},{
                    		xtype: 'displayfield'
                    		,value: 'Manager'
           //         		,width: 120
                    	}]
                    },{
                    	xtype: 'compositefield'
                    	,items: [{
                    		name: 'lblGuests'
                    		,xtype: 'textfield'
                    		,value: ''
                    	},{
                    		name: 'lblManger'
                    		,xtype: 'textfield'
                    		,value: ''
                    	}]
                    },{
                    	xtype: 'orders-grid-units'
                    	,preventRender: true
                    }]
                }]	
            }]
            ,listeners: {
            	render: function(p) {
            		Ext.Ajax.request({
      				 url: Orders.config.connectorUrl ,
       				 success: function(t){ 
         			   	 var jsonData = Ext.util.JSON.decode(t.responseText);
         			   	 var descr = jsonData.results[0].descr;
         			   	 descr = descr.split(',');
         			   	 var kolvo = jsonData.results[0].kolvo;
         			   	 kolvo = kolvo.split(',');
         			   	 var price = jsonData.results[0].price;
         			   	 price = price.split(',');
         			   	 var myData = new Array();
         			   	 for (var i=0; i < descr.length; i++) {
         			   	 	myData[i] = descr[i] + ',' + price[i] +',' + kolvo[i];
         			   	 };
         			   	 console.log(myData);
         			   	 p.getForm().setValues({ 'lblFirstName': jsonData.results[0].name, 'lblLastName': jsonData.results[0].lastname, 'lblMiddleName': jsonData.results[0].middlename, 'lblAge': jsonData.results[0].age, 'lblPhone': jsonData.results[0].phone, 'lblEmail': jsonData.results[0].email, 'lblPartyDate': jsonData.results[0].partydate, 'lblMesto': jsonData.results[0].mesto, 'lblGuests': jsonData.results[0].guests, 'lblManger': jsonData.results[0].manger});
         			   	 var store = new Ext.data.ArrayStore({
            			 id: 10
            			 ,fields: [
            			 	{name: 'company'},
               				{name: 'price'},
               				{name: 'change'}
            				]
        				 });
        				 store.loadData(myData);
        				 console.log(store);
    //    				 if(Ext.getCmp('orders-grid-units') != null) Ext.get('orders-grid-units');		I want renew LocalGrid with store
        				 }
      			 	 ,params: { action: 'mgr/order/getinfo', query: MODx.request.id }
    				 });
            	}
            }
        });
        Orders.panel.Info.superclass.constructor.call(this,config);
    };
    Ext.extend(Orders.panel.Info,MODx.FormPanel);
    Ext.reg('orders-panel-info',Orders.panel.Info);
    
    Orders.grid.Units = function(config) {
        var myData = [
            ['3m Co',                               71.72, 0.02],
            ['Alcoa Inc',                           29.01, 0.42],
            ['United Technologies Corporation',     63.26, 0.55],
            ['Verizon Communications',              35.57, 0.39],            
            ['Wal-Mart Stores, Inc.',               45.45, 0.73]
        ];
        var store = new Ext.data.ArrayStore({
            fields: [
               {name: 'company'},
               {name: 'price',      type: 'float'},
               {name: 'change',     type: 'float'},
            ]
        });
    
        // manually load local data
        store.loadData(myData);
        config = config || {};
        Ext.applyIf(config,{
            id: 'orders-grid-units'
            ,store: store
    //        ,url: Orders.config.connectorUrl
    //        ,baseParams: { action: 'mgr/order/getList' }
            ,fields: ['id','lastname','name', 'age']
            ,paging: true
    //        ,autosave: true
    //        ,remoteSort: true
            ,anchor: '97%'
            ,autoExpandColumn: 'name'
            ,columns: [{
                header: 'Company'
                ,dataIndex: 'company'
                ,sortable: true
                ,width: 80
                ,editor: {xtype:'textfield'}
            },{
                header: 'Price'
                ,dataIndex: 'price'
                ,sortable: true
                ,width: 80
                ,editor: { xtype: 'textfield' }
            },{
                header: 'Change'
                ,dataIndex: 'change'
                ,sortable: true
                ,width: 40
                ,editor: { xtype: 'textfield' }
            }]
    /*        ,tbar: [{
            	xtype: 'textfield'
            	,id: 'orders-search-filter'
            	,emptyText: 'Serch...'
            	,listeners: {
            		'change': {fn:this.search,scope:this}
            		,'render': {fn: function(cmp) {
            			new Ext.KeyMap(cmp.getEl(), {
            				key: Ext.EventObject.ENTER
            				,fn: function() {
            					this.fireEvent('change', this);
            					this.blur();
            					return true;
            				}
            				,scope: cmp
            			});
            		},scope: this}
            	}
            }]	*/
        });
        Orders.grid.Units.superclass.constructor.call(this,config);
    };
    Ext.extend(Orders.grid.Units,MODx.grid.LocalGrid);
    Ext.reg('orders-grid-units',Orders.grid.Units);
    [ed. note: electroid last edited this post 14 years, 4 months ago.]
      from Russia with love
      • 33968
      • 863 Posts
      You're currently creating a new store when receiving the ajax success response, but it's not associated with your grid at all.

      What you need to do is get a reference to the existing grid store, then load it with your new data. Something like this:
      // this replaces lines 164-174 of your code above
      var grid = Ext.getCmp('orders-grid-units');
      var store = grid.getStore();
      store.load(myData);
      grid.refresh();
      
        • 38954
        • 24 Posts
        Thanks for reply Lucas!
        When i use grid.refresh i see cannot call metod request in console and loading window in grid.
        I think refresh() send request, instead of just show my data, even i use Local.Grid.
          from Russia with love
          • 33968
          • 863 Posts
          Hmmm, not sure - but why don't you use a normal grid (MODx.grid.Grid) as you are loading the data from the server anyway?
            • 38954
            • 24 Posts
            Ok, i try it works, but how can i put my data in every row now, since in my database one row have a string with multiple values like this: "value, value1, value2".
            I start play with render, but this doesn't do the job

            ,renderer:function(value){
                 			   	 descr = value.split(',');
                 			   	 var myData = new Array();
                 			   	 for (var i=0; i < descr.length; i++) {
                 			   	 	myData[i] = descr[i];
                 			   	 };
                 			   	 return myData;
              from Russia with love
              • 33968
              • 863 Posts
              First of all, your grid fields need to match the data keys:
              // line 210
              ,fields: [''company','price', 'change']
              


              You need to iterate over your data in your ajax processor and return it like this:
              // insert code here to get your data into the following array
              $list = array(
                  array(
                      'company' => '3m Co',
                      'price' => 71.72,
                      'change' => 0.02,
                  ),
                  array(
                      'company' => 'Alcoa Inc',
                      'price' => 29.01,
                      'change' => 0.42,
                  ),
              );
              $count = count($list);
              
              return '{"total":"'.$count.'","results":'.$this->modx->toJSON($list).'}';
              

              $count is the total number of results, calculated independently of paging.
                • 38954
                • 24 Posts
                Lucas, thank you for accompaniment in component devolopment.
                Finally i create additional table in schema and now i grab all grid info from there.
                Thx!
                  from Russia with love