Reputation: 1
Hi I have the following xml returned from the server: Code:
I couldn''t seem to get the xml store configuration right. Especially, I want to be able to obtain the custom tags: name, intra and referrals which are properties of the result set returned. Many thanks!
Upvotes: 0
Views: 3353
Reputation: 381
Try this code (replace test.xml with your xml source)
// create the Data Store
var store = new Ext.data.Store({
// load using HTTP
url: 'test.xml',
// the return will be XML, so lets set up a reader
reader: new Ext.data.XmlReader({
// records will have an "customer" tag
record: 'customer',
}, ['id','field1', 'field2', 'field3'])
});
// create the grid
var grid = new Ext.grid.GridPanel({
store: store,
columns: [
{header: "id", width: 120, dataIndex: 'id', sortable: true},
{header: "field1", width: 180, dataIndex: 'field1', sortable: true},
{header: "field2", width: 115, dataIndex: 'field2', sortable: true},
{header: "field3", width: 100, dataIndex: 'field3', sortable: true}
],
renderTo:'example-grid',
width:540,
height:200
});
store.load();
in order to obtain the tags: name, intra and referrals i used Ext.DomQuery which enables you to parse to xml (try it for intra and referrals )
Ext.Ajax.request({
url: 'test.xml',
success: function(response){
console.debug(response);
if (Ext.DomQuery.selectNode("/rootNode/name", response.responseXML)) {
var name = Ext.DomQuery.selectValue("/rootNode/name", response.responseXML);
console.debug(name);
}
},
failure: function () { console.log('failure');}
});
Upvotes: 0