PDA

View Full Version : Submit Data from GridPanel with CheckboxSelectionModel



reuadism
23 May 2012, 12:03 AM
Hi everyone,

i'am relatively new to ExtJS and Javascript so i'am not really familar to best pratices by far.

I have a simple data.Store like this


var store = new Ext.data.Store({
url : '/servletURLtoGetData',
reader : new Ext.data.XmlReader({

/* config of my reader */

})
});


Furthermore I have a ColumnModel and a CheckboxSelectionModel.


var sm = new Ext.grid.CheckboxSelectionModel({
});

var cm = new Ext.grid.ColumnModel({
columns : [{

column1

}, {

column2

}, {

column3

}, sm]
});


The GridPanel which uses these components looks like this:


var gp = new Ext.grid.GridPanel({
store : store,
cm : cm,
sm : sm,
width : 561,
height : 400
});


Now I added the GridPanel to my Panel:


var fp = new Ext.Panel({
renderTo : 'view',

cls : 'left-right-buttons',

frame : 'true',
layout : {

type : 'table',
columns : 1

},

width : 573,

height : 485,

items : [lHead, lText, gp, bNext]
});


What I want to do is get all checked items from the GrinPanel and send all the releated data to my servlet. Preferred as Xml.

I allready managed to send the data via JSON, but I didn't find a encode method for Xml like it is available for JSON.

My JSON solution looks like this:

var bNext = new Ext.Button({
text : 'Next',

width : 75,

cls : 'buttonRight',

handler : function() {

var records = sm.getSelections();
var choices = [];




for (var i = 0; i < records.length; i++) {

choices.push(records[i].data);

}


var choicesJSON = Ext.util.JSON.encode(choices);


var conn = new Ext.data.Connection();

conn.request({

url : 'servletURLtoPostData',

params : {

action : 'post',
data : choicesJSON
},

success : function() {

},

failure : function() {

}

});

}
});


Is there any possibility to send the data as Xml?
I hope you understand what I want to do /:)

Thanks in advance,
reuadism.

willigogs
23 May 2012, 12:52 AM
To send and receive data as XML, I believe you would need to use the xmlstore, possibly using xmlreader and xmlwriters:
http://docs.sencha.com/ext-js/3-4/#!/api/Ext.data.XmlStore

sword-it
29 May 2012, 7:16 AM
Hi,

It would be better to convert JSON data to XML in the server side.

You can post your JSON object as a string using below method:



Ext.Ajax.request({
....


params: { json: Ext.util.JSON.encode({ values: { name: "Jack" }}) }


....

});

It will be converted as:
<values>
<name>Jack</name>

</values>


OR

try to google for a js code which converts JSON to XML as a string.

Regards.