PDA

View Full Version : XMLDataModel



techno_adi
11 Oct 2006, 1:26 AM
Hi
I am having problems in populating my grid using xmldatamodel. Can somebody show me a way out?
here is the part for creating the grid


var urlColList = [
{header: "Feeds", width: 180, sortable: true},
{header:"Link", width: 20, sortable: false} // this would be hidden
];
var urlCM = new YAHOO.ext.grid.DefaultColumnModel(urlColList);

var urlSchema = {
tagName: 'site',
id: 'use-index',
fields: ['feed','link']
};
this.urlDM = new YAHOO.ext.grid.XMLDataModel(urlSchema);
this.urlDM.setDefaultSort(urlCM, 1, 'ASC');

this.urlSM = new YAHOO.ext.grid.SingleSelectionModel();
this.urlSM.onRowSelect.subscribe(this.loadFeedUrl, this, true);
this.urlGrid = new YAHOO.ext.grid.Grid('feed-list', this.urlDM, urlCM, this.urlSM);
this.urlGrid.render();

this.urlDM.load('FeedListReader.ashx');
if(this.urlDM.getRowCount() >= 1){
this.urlSM.selectFirstRow();
}
else
alert("Ihave no data"); //WHY IS THIS COMING UP?

also my FeedListReader.ashx file is returning following as a response
(tested by directly typing the path on the browser)


- <root>
- <site>
<feed>Ajaxian</feed>
<link>http://feeds.feedburner.com/ajaxian</link>
</site>
- <site>
<feed>YUI Blog</feed>
<link>http://feeds.yuiblog.com/YahooUserInterfaceBlog</link>
</site>
- <site>
<feed>JSB Blog</feed>
<link>http://www.jackslocum.com/yui/feed/rss/</link>
</site>
</root>


can any body tell me why the grid doesn't show up any data.

Thanks a lot

jack.slocum
11 Oct 2006, 1:36 AM
this.urlDM.load('FeedListReader.ashx'); <-- this is an async call
if(this.urlDM.getRowCount() >= 1){ <-- this code is executed immediately,
before load finishes so always empty
this.urlSM.selectFirstRow();
}
else
alert("Ihave no data"); //WHY IS THIS COMING UP? <-- that is immediate too


Since it's an async call, you will need to wait for the load event to make your check:


var onLoad = function(dm){
if(dm.getRowCount() > 0){
this.urlSM.selectFirstRow();
}
else
alert("Ihave no data");
};
this.urlDM.addListener('load', onLoad, this, true);
this.urlDM.load('FeedListReader.ashx');

techno_adi
11 Oct 2006, 2:09 AM
changed the datamodel to this


this.urlDM = new YAHOO.ext.grid.XMLDataModel(urlSchema);
this.urlDM.setDefaultSort(urlCM, 1, 'ASC');
this.urlDM.addListener('load', onUrlLoad, this, true);
this.urlSM = new YAHOO.ext.grid.SingleSelectionModel();
this.urlSM.onRowSelect.subscribe(this.loadFeedUrl, this, true);
this.urlGrid = new YAHOO.ext.grid.Grid('feed-list', this.urlDM, urlCM, this.urlSM);
this.urlGrid.render();

this.urlDM.load('http://www.jackslocum.com/blog/examples/feed.php',{feed: 'http://localhost/feed/feedlist.xml'}); //refering jacks php file to get the file on my server

and the function...

onUrlLoad : function() {
if(this.urlDM.getRowCount() >= 1){
this.urlSM.selectFirstRow();
}
else
alert("Ihave no data");
this.urlwait.hide();
}


the urlwait icon never hides.. infact no data is shown up. rest all the code remains same

jack.slocum
11 Oct 2006, 3:13 AM
Ah, you also have an infinite loop.

onLoad selects the first row, rowSelect causes it to load the feed. This will loop forever.

techno_adi
11 Oct 2006, 3:28 AM
oh no..
wait a minute..infinite loop.. I didn't get it where?
Actually, i added the reference to your feed.php just to get the "xml" file as response [ i guess that whats your php is doing] irrespective of it being a "rss feed" or a simple xml file like mine...

The scene here is i have two grids in place
This grid just holds a list of "rss feed" site available/subscribed
The second grid [which is not shown here, but is exact copy of your feed-grid.js file] loads the actual feeds from the site..

Now, initially i just want to load the feed-list grid with the list of site links which is a simple xml file shown above.
Once i click on the row, it actually passes the link of the site to load all the available feeds in the second grid

Now, for my question..
I didn't get the infinite loop part, please can you explain a bit..
sorry for the trouble
thanks

jack.slocum
11 Oct 2006, 4:01 AM
I just saw, you have two grids and the first grid is loading the 2nd grid, not the first. Ok, so maybe no infinite loop.

I don't know whats wrong. Did you check to make sure you are actually receiving data?

techno_adi
11 Oct 2006, 4:38 AM
How do i check that?

BTW.. one silly question : at the place of "onLoad", can i provide my custom function name
onUrlLoad? I am asking this coz.. i am getting a crazy error saying onUrlLoad undefined although i have the definition.

I am totally out on XMLDataModel..
Can I have a simple example, wherein a simple xml file is being loaded to the grid ( and not the rss)
anybody please?

techno_adi
12 Oct 2006, 2:49 AM
hi,
can any one tell me the significance of the following line in a xml file (sheldon.xml from grid part-2 post)



<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)"/>
</HTTPHeaders>

this would be in relation to the XmlDataModel
if i have a simple xml file will it not work?

jack.slocum
12 Oct 2006, 5:34 AM
That's stuff amazon throws in when you do a search. They are insignificant.

techno_adi
12 Oct 2006, 5:39 AM
Hi Jack,

Does YUI controls like menu etc.. support some thing like XmlDataModel, so that i can specify the content to be loaded from a file on server

jack.slocum
12 Oct 2006, 5:53 AM
Not that I know of. But there's no reason you can't load using the datamodel and then loop through the rows and add them to a menu.

techno_adi
12 Oct 2006, 6:01 AM
This sounds interesting.. :)
If you can, please give me a start on this.
I mean how would i go about the nesting of menus/ trees etc..?
Actually, i have to make all the components on my form dynamic(server side load)
Now i was wondering to write a different xml parser :!: