PDA

View Full Version : How to configure Grid for xml to show data?



saadkhan
27 Feb 2010, 11:54 PM
Hello,
I have an xml which is passed through some javascript function to show it in a grid of mine. I know the structure of my xml (to be shown) but few tags inside known a tag are not confirmed whether which will exist and which not. Like:



<Statuses>
<Status DateAndTime='11/5/2009 10:11:59 PM'>
<Door State='1' Description='Doors are closed' />
<Engine State='0' Description='Engine is off' />
</Status>
<Status DateAndTime='12/5/2009 8:26:21 AM'>
<Speed State='0' Description='0 km/hr' />
<Battery State='1' Description='Battery full' />
</Status>
</Statuses>


I tried doing this but didnt work:



function MakeGrid()
{
var recData =[];
recData.push(new Ext.data.Field({name: 'Description', mapping: 'Door > @Description'})); // hardcoded for testing
var myReader =new Ext.data.XmlReader(
{
record: 'Status'
}, recData);

var columns =[];
columns.push(new Ext.data.Record({header :"Description", dataIndex :'Description', width :100}));
Ext.StoreMgr.get('statusStore').reader = myReader;
Ext.getCmp('statusGrid').columns = columns;
store.loadData(StringToXml(strrr), true);
store.load();
Ext.getCmp('statusGrid').store.on('load',Ext.getCmp('statusGrid').autoSizeColumns,Ext.getCmp('statusGrid'));
}

Ext.onReady(function() {

var statusStore = new Ext.data.Store({
storeId: 'statusStore',
proxy: new Ext.data.MemoryProxy(''),
reader: new Ext.data.XmlReader(
{
record: 'Status'
},
[
{name: 'State', mapping: 'Door > @State'},
{name: 'Description', mapping: 'Door > @Description'}
])
});

var statusGrid = new Ext.grid.GridPanel({
id: 'statusGrid',
title: 'Status',
store: statusStore,
deferredRender: false,
hideHeaders: true,
columns: [
{header: "Door", dataIndex: 'State', resizeable: true, sortable: false, renderer: function(value,p,r){ return String.format("<b>{0}</b><br />{1}<br />{2}"), value, r.data['State'], r.data['Description'] }}
],
viewConfig:{ forceFit: true }
});




});


My xml would be like this, in which tags may vary inside <Status> tag but will be among known tags. I dont have any idea how to configure XMLReader, Store and grid on runtime to make this data show in my grid. However, I have made another pre-configured grid which shows data all fine. But How and What can I do in this situation?