PDA

View Full Version : How to show data in gridpanel from a variable having xml?



saadkhan
21 Feb 2010, 12:23 PM
Hello,
I need to show xml data in gridpanel. I have some javascript method 'showData' in which I used to get my xml data. Now I want to show that data in my gridpanel 'grid' everytime 'showData' function is called. This function is outside of Ext.onload event function.
First I tried by hardcoding xml data to a variable and attempted, but i cant do this....Here is my code (using sample xml):



function showData(str)
{
Ext.getCmp('grid').getStore().load();
}


var vvv =
'<ItemSearchResponse xmlns="http://webservices.amazon.com/AWSECommerceService/2006-06-28">' +
'<OperationRequest>' +
'<HTTPHeaders>' +
'<Header Name="UserAgent"' +
'Value="Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Avant Browser; Avant Browser; .NET CLR 1.0.3705; .NET CLR 2.0.50727; .NET CLR 1.1.4322; Media Center PC 4.0; InfoPath.2)"></Header>' +
'</HTTPHeaders>' +
'<RequestId>18CZWZFXKSV8F601AGMF</RequestId>' +
'<Arguments>' +
'<Argument Name="Service" Value="AWSECommerceService"></Argument>' +
'<Argument Name="AssociateTag" Value="ws"></Argument>' +
' <Argument Name="SearchIndex" Value="Books"></Argument>' +
' <Argument Name="Author" Value="Sidney Sheldon"></Argument>' +
' <Argument Name="SubscriptionId" Value="1A7XKHR5BYD0WPJVQEG2"></Argument>' +
' <Argument Name="Version" Value="2006-06-28"></Argument>' +
' <Argument Name="Operation" Value="ItemSearch"></Argument>' +
'</Arguments>' +
'<RequestProcessingTime>1.05041599273682</RequestProcessingTime>' +
'</OperationRequest>' +
'<Items>' +
'<Request>' +
'<IsValid>True</IsValid>' +
'<ItemSearchRequest>' +
'<Author>Sidney Sheldon</Author>' +
'<SearchIndex>Books</SearchIndex>' +
'</ItemSearchRequest>' +
'</Request>' +
'<TotalResults>203</TotalResults>' +
'<TotalPages>21</TotalPages>' +
'<Item>' +
'<ASIN>0446355453</ASIN>' +
'<DetailPageURL>' +
'http://www.amazon.com/gp/redirect.html%3FASIN=0446355453%26tag=ws%26lcode=xm2%26cID=2025%26ccmID=165953%26location=/o/ASIN/0446355453%253FSubscriptionId=1A7XKHR5BYD0WPJVQEG2' +
'</DetailPageURL>' +
'<ItemAttributes>' +
'<Author>Sidney Sheldon</Author>' +
'<Manufacturer>Warner Books</Manufacturer>' +
'<ProductGroup>Book</ProductGroup>' +
'<Title>Master of the Game</Title>' +
'</ItemAttributes>' +
' </Item> ' +
'</Items>' +
'</ItemSearchResponse>';



Ext.onReady(function() {

var red = new Ext.data.XmlReader(
{
record: 'Item',
id: 'ASIN',
totalRecords: '@total'
},
[
{name: 'Author', mapping: 'ItemAttributes > Author'},
'Title', 'Manufacturer', 'ProductGroup'
]
);

var routeStore = new Ext.data.Store({
proxy: new Ext.data.MemoryProxy(vvv),
reader: red
});

var grid = new Ext.grid.GridPanel({
id: 'routeGrid',
store: routeStore,
columns: [
{header: "Author", width: 120, dataIndex: 'Author', sortable: true},
{header: "Title", width: 180, dataIndex: 'Title', sortable: true},
{header: "Manufacturer", width: 115, dataIndex: 'Manufacturer', sortable: true},
{header: "Product Group", width: 100, dataIndex: 'ProductGroup', sortable: true}
],
renderTo:'myDiv',
enableHdMenu : false,
width:540,
height:200
});

});



I checked that Ext.getCmp('grid').getStore().proxy.data is returning my xml data but not showing

Animal
21 Feb 2010, 12:28 PM
A String containing XML markup != XML.

Read it from a server. If you MUST code XML into your page (??????) then you will have to parse it into a document.

Also. totalRecords: '@total'? The total attribute of what element contains the size of the entire dataset?

saadkhan
22 Feb 2010, 2:58 AM
Thanks alot.... :)
Now i got to know wht rubbish i was doing from 3 days....
Now i have successfully done it. Now, I tried very same thing with my own XML markup that is like this:


<Markers>
<Lines>
<Point Latitude='123.321' Longitude='321.123' Location='gulshan' DateAndTime='10-10-2009 12:21:15' Speed='0 km/h' />
<Point Latitude='123.321' Longitude='321.123' Location='nipa' DateAndTime='10-10-2009 12:21:15' Speed='10 km/h' />
</Lines>
</Markers>

For this, I configured XmlReader and GridPanel appropriately, so, rows appears in grid but not data (that is empty rows). Here is what I am trying:


routeStore = new Ext.data.Store({
proxy: new Ext.data.MemoryProxy(''),
reader: new Ext.data.XmlReader(
{
record: 'Point'
},
[
{name: 'Location', mapping: 'Point > Location'},
'Speed', 'DateAndTime', 'Latitude', 'Longitude'
])
});

var routeGrid = new Ext.grid.GridPanel({
title: 'Route',
store: routeStore,
columns: [
{header: "Location", width: 120, dataIndex: 'Location', sortable: true},
{header: "Speed", width: 180, dataIndex: 'Speed', sortable: true},
{header: "DateAndTime", width: 115, dataIndex: 'DateAndTime', sortable: true},
{header: "Latitude", width: 100, dataIndex: 'Latitude', sortable: true},
{header: "Longitude", width: 100, dataIndex: 'Longitude', sortable: true}
],
height: 300
});

Please note that I am loading my Store from somewhere else!!!

Animal
22 Feb 2010, 3:01 AM
Heh! Looks like you are working on the same kind of app as me?

Dynamically updating maps with position markers of GPS units?

Do you have a problem? I can't tell.

saadkhan
22 Feb 2010, 3:13 AM
Do you have a problem? I can't tell.
Lolz......so rude man :)
Yeah, I am almost at same work as you i guess....When I read your first line, I thought of some ideas sharing stuff but you put yourself away from everything and didnt even help too.
anyway best of luck for ur app!

Animal
22 Feb 2010, 3:22 AM
Eermmm what????

I can't read a problem in your post!

Ask a question. State your problem.