PDA

View Full Version : How to load the store from a form load xml response...help me please



nndong89
26 May 2011, 8:59 AM
Hi everyone,I'm a newbie,i've just searching about ExtJS so i have problem to load a store from XMLresponse

This is the responseXML when i click the button "test" :

<?xml version='1.0' encoding='utf-8'?>
<dataset>
<row><gid>1</gid><id_huyen>697</id_huyen><danso>62113</danso></row>
..............................................................................................................
<row><gid>10</gid><id_huyen>697</id_huyen><danso>62113</danso></row>
</dataset>

Button text :
action = new GeoExt.Action({
text: 'test',
name: 'abc',
handler: function(){
var result ;
OpenLayers.loadURL("./connect.jsp",result,this,test,test);
function test(response){
if(response && response.responseText){
//alert(response.responseText);
var XMLStore=response.responseText;
alert(XMLStore);
}
else{
alert("wrong");
}

}
}
//------> What i continue to do to setup a XMLStore to the GridPanel

});

And this is the GridPanel i using the XML:

var grid = new Ext.grid.EditorGridPanel({
store: XMLStore,
columns: [
{header: "GID", dataIndex: 'gid'},
{header: "HUYEN", dataIndex: 'id_huyen'},
{header: "DANSO", dataIndex: 'danso'},
]
});

jorgeluislay
27 May 2011, 2:52 AM
i would say, you need a store with a reader wihch contains what you need for the columns.

that means:

var XMLStore = new Ext.data.Store({
url: 'xmlStore.xml',
reader: new Ext.data.XmlReader({
record: 'dataset',
id:'gid'
},[
'',
'id_huyen',
'danso'
]),
groupField:'size',
sortInfo:{field:'name', direction:'ASC'},
remoteSort: true,
autoLoad: true
});

im not sure what you exatly want to do with this button but a grid needs a reader, store and a url.

nndong89
27 May 2011, 7:39 AM
Thanks for reply
I mean that,i want when i click the button the XMLreponse will load into the Grid,but i don't have a XML file,the XML is the reponse from the server.
I understand your answer but my problem is "the XML is the reponse from sever" not "a file",please help me

skirtle
28 May 2011, 2:50 PM
To load data from the server you just need to set the url config option on your store. e.g.:


var store = new Ext.data.XmlStore({
url: './connect.jsp',
...
});

This will create an HttpProxy that loads the XML from the server by calling connect.jsp over Ajax. See the ExtJS docs for more.