PDA

View Full Version : How to retrive data From Editable grid which using JsonStore ?



srinivasp
8 Dec 2009, 2:14 AM
Hi
I am using grid with jsonStore. I want to save the grid data into data base. For this i am passing grid data like grid.getStore().reader.jsonData and catching this into Json Array.When i am reading elements from Json Array i am getting String element . But i am expecting Json Object .......

Please help me how to read and save the grid data.......

Thanks in Advance

MiamiCoder
8 Dec 2009, 1:28 PM
I'm afraid your question is a little hard to understand. Let me respectfully suggest that you spend some time looking at the grid examples in the samples and demos page (http://www.extjs.com/deploy/dev/examples/samples.html) so you can get familiar with the best practices for using the editable grid.

I would also suggest that you post some sample code so we can have a better picture of the problem.

srinivasp
8 Dec 2009, 11:15 PM
hi
Find my code here
var store= new Ext.data.JsonStore({
fields: [
{name: 'incomeItem'},
{name: 'amount'},
{name: 'desc'},
{name: 'freq'},
{name: 'ccy'},
{name: 'stYr'},
{name: 'endYr'},
{name: 'grRt'},
{name: 'consRetire',type:'bool'},
{name: 'consInsu',type:'bool'},
{name: 'owner'},
]
});

incomeGrid=new Ext.grid.EditorGridPanel({
store: incomeStore,
renderTo:'incomeDetailsInput',
trackMouseOver:true,
resizable:true,
collapsible : true,
layout:'accordion',
columnLines : true,
loadMask: true,
autoWidth : true,
width:900,
autoScroll:true,
viewConfig: {forceFit: true},
plugins: [retCkBox,insCkBox],
tbar: [{
iconCls: 'icon-user-add',
text: 'Add',
handler: function(){
var row = incomeGrid.getStore().recordType;
var p = new row({
incomeItem:'Please Select...',
consRetire:false,
consInsu:false});
var rec = incomeGrid.getStore().getAt(0);
var status = recordCheck(rec);
if(status)
{
incomeGrid.stopEditing();
incomeStore.insert(0, p);
incomeGrid.startEditing(0, 0);
}
}
},{
ref: '../removeBtn',
iconCls: 'icon-user-delete',
text: 'Remove',
disabled: false,
handler: function(){
incomeStore.remove(incomeGrid.getStore().getAt(rowNumber));
incomeGrid.reconfigure(incomeStore,incomeGrid.getColumnModel());
}
}],
columns: [
{id:'incomeItem',header: 'Income Item', width: 120, sortable: true, dataIndex: 'incomeItem',editor:comboIncome},
{id:'amount',header: 'Amount', width: 70, sortable: true, dataIndex: 'amount',editor: new Ext.form.NumberField({allowBlank: false}),
renderer: function(v, params, record){

if(typeof record.data.amount!='undefined')
{
var tt = FComma(record.data.amount);
return tt;
}
}
},
{id:'desc',header: 'Description', width: 100, sortable: true, dataIndex: 'desc',editor: new Ext.form.TextField({allowBlank: true})},
{id:'freq',header: 'Frequency', width: 60, sortable: true, dataIndex: 'freq',editor: ComboFreq},
{id:'ccy',header: 'Currency', width: 60, sortable: true, dataIndex: 'ccy',editor: comboCCY},
{id:'stYr',header: 'Start Year', width: 60, sortable: true, dataIndex: 'stYr',editor: new Ext.form.NumberField({allowBlank: false}),
renderer: function(v, params, record){
//incomeGrid.reconfigure(incomeStore,incomeGrid.getColumnModel());
//alert(record.data.stYr);
validateF('stYr',record.data.stYr);
return record.data.stYr;
}
},
{id:'endYr',header: 'End Year', width: 60, sortable: true, dataIndex: 'endYr',editor: new Ext.form.NumberField({allowBlank: false})},
{id:'grRt',header: 'Growth Rate', width: 50, sortable: true, dataIndex: 'grRt',editor: new Ext.form.NumberField({allowBlank: false})},
retCkBox,
insCkBox,
{id:'owner',header: 'Owner Of Income', width: 120, sortable: true, dataIndex: 'owner',editor: comboOwner}
],
stripeRows: true,
autoHeight:true//,
//autowidth:true

});





I Have save button........

When i click on save i am passing grid data to java using DWR call like....

DWRDao.saveIncomeExpDetails(store.reader.jsonData,{
async:false,
callback:function(str)
{
alert('str')
});

in java I am catching the input of grid into json Array

my java Function is....Here i am getting error in retriving the data from json array into json Objects

public String saveIncomeExpDetails(JSONArray arr,String fnaID,String type,String brCd) throws Exception{

System.out.println("array size........."+arr.size());// Coming correct
JSONObject obj=new JSONObject();
for(int i=0;i<arr.size();i++)
{
obj=arr.getJSONObject(i);// Here I am getting error saying arr[0] is String not a JSONObject.
}


}

Here my idea is retrive the data row by row and store it into database table using insert statement.

Please Help me in resolving this issue.