PDA

View Full Version : Grid inside a form Panel -> How to share the store loaded



rogerio.carrasqueira
16 Dec 2010, 11:28 AM
Hello Everybody!

I'm having some problems to work grid inside form panels. I have a form that is about sales and sales itens where it opens on window. Let me describe this window: on the first field set I have fields about the sale master data like vendor, customer, etc... below I have another field where appear a grid where I have all itens that belongs to this sale. On this window I want to load all data in one shot on a JSON like this:



{
"data": {
"customer": 1,
"advertiser": 1,
"name": "asddasd",
"total_value": "0.00",
"user": 1,
"pk": 61,
"status_sale": 1
},
"success": true,
"saleItens": [{
"pk": 4,
"model": "salesflow.saleitem",
"fields": {
"total_item": "0.00",
"price_retail": "0.00",
"ends_date": "2010-12-18 00:00:00",
"start_date": "2010-12-16 00:00:00",
"impressions_amount": 0,
"sale": 61,
"percent_discount": 0.0,
"inventory": 2,
"price_cost": "0.00",
"discount_value": "0.00",
"commercial_mode": 4,
"price_sale": "0.00"
}
}]
}
Pay attention that I have two roots on my json, the first on (called root), will be used to show the data at the form and the second (saleItens) will feed the grid, the loading data to the form fields is working good, there is no problem about it, my problem is the load data to the grid store. I'm using this way to load the data to the form, it is an override at the form panel


show: function(){
//super
saleWindow.superclass.show.apply(this,arguments);

if(this.saleID !== 0){ //se tem sale

this.btnDelete.show();
this.el.mask('Carregando informações');

this.formPanel.getForm().load({

url : '/salesflow/json/sale/show/',
params : {
action : 'show',
pk : this.saleID
},
scope : this,
success: function(){

// Here I would like to pass the Json that I have loaded to the form to my grid using the one shot concept

this.el.unmask();
this.saleItemStore.load();
},
failure: function(request){
showError(request.result.message, 'Ops!!')
this.el.unmask();
}

});



}
else {
this.btnDelete.hide();
this.formPanel.getForm().reset();

}
},And above on this code I have the store definition at initComponent at my formPanel




initComponent: function(){

this.saleItemStore = new Ext.data.JsonStore({
url : '/salesflow/json/sale/show/',
params : {
pk : this.saleID
},

idProperty: 'pk',
root: 'saleItens',

fields : [
{
name: 'pk',
type: 'int',
},
{
name: 'site',
type: 'int',
mapping: 'fields.site',
validator: 'notblank',
allowBlank: false
}
]
});

So, my goal is how to share the load json store with form and grid on the same time? Is it possible?

Thanks a lot!

Rogério Carrasqueira

rogerio.carrasqueira
20 Dec 2010, 6:34 PM
Its very simple:

At show closure do:


success: function(form, action){ -< this will share the stores
this.el.unmask();
this.saleItemStore.loadData(action.result);
}