PDA

View Full Version : Grid data into spring controller



jocatastar
20 Feb 2014, 4:24 AM
Hi ,

I have problem with extjs grid , I want to send grid data record as a json object ,


my grid all fields all editable , and it's have many records , I want to save in database table ,

could you give easy solution for ths problem,

Thanks & Regards,
Yakambram Sai

scottmartin
20 Feb 2014, 6:40 AM
This is handled by your proxy. Here is a quick setup that show how the data is sent in the header you modify a field
Check the header on your Network/xhr tab in your debugger and then inspect the header for update.php error call

This just shows the client side, you would need to address the incoming data on your server side.



{
'items': [
{
'name' : 'Lisa',
'email' : 'lisa@simpsons.com',
'change' : 80
},
{
'name' : 'Bart',
'email' : 'bart@simpsons.com',
'change' : 20
},
{
'name' : 'Homer',
'email' : 'home@simpsons.com',
'change' : 23
},
{
'name' : 'Marge',
'email' : 'marge@simpsons.com',
'change' : -11
}
]
}




Ext.define('MyModel', {
extend : 'Ext.data.Model',

fields : [
{ name: 'name' },
{ name: 'email' },
{ name: 'change' }
]
});

Ext.onReady(function(){

var store = Ext.create('Ext.data.Store', {
autoLoad : true,

autoSync : true,

model : 'MyModel',
proxy : {
type : 'ajax',

//url : 'data.json',

api : {
read : 'data.json',
create : 'create.php',
update : 'update.php',
destroy : 'destroy.php'
},

reader : {
type : 'json',
root : 'items'
}
}
});


var cellEditing = Ext.create('Ext.grid.plugin.CellEditing', {
clicksToEdit : 1
});

Ext.create('Ext.grid.Panel', {
title : 'Simpsons',
store : store,
selModel : {
selType: 'cellmodel'
},
columns : [
{ header : 'Name', dataIndex : 'name', editor : { xtype : 'textfield' } },
{ header : 'Email', dataIndex : 'email', flex : 1, editor : { xtype : 'textfield' } },
{ header : 'Change', dataIndex : 'change', editor : { xtype : 'textfield' } }
],
height : 200,
width : 400,
renderTo : Ext.getBody(),

plugins : [ cellEditing ]

});

});

jocatastar
20 Feb 2014, 9:41 PM
my problem is different , my screen window have many grids those all are editable and I have separate button to save , when I click on that button those grid values should be save in data base table record wise

brian428
20 Feb 2014, 10:20 PM
It's not clear what you actually want to know.

If you're asking about sending the JSON data to the server, look at the store's sync() method.

If you're asking how to handle saving the JSON data on the server side, that really has nothing to do with Ext JS. Use whatever mechanism your chosen platform provides to parse incoming JSON data and persist it. How that is done depends entirely on your server-side setup.