This DataTable is populated with XML data from a webservice that is held in local memory in the JavaScript variable xmlDoc.
Data:
1 | <?xml version="1.0"?> |
2 | <ResultSet xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:yahoo:lcl" xsi:schemaLocation="urn:yahoo:lcl http://api.local.yahoo.com/LocalSearchService/V2/LocalSearchResponse.xsd" totalResultsAvailable="665" totalResultsReturned="10" firstResultPosition="1"> |
3 | <ResultSetMapUrl>http://local.yahoo.com/mapview?stx=pizza&csz=Sunnyvale%2C+CA+94089&city=Sunnyvale&state=CA&radius=15&ed=9brhZa131DwigChqKlCo22kM1H_9WgoouCr87Ao-</ResultSetMapUrl> |
4 | <Result> |
5 | <Title>Pizza Depot</Title> |
6 | <Address>919 E Duane Ave</Address> |
7 | <City>Sunnyvale</City> |
8 | <State>CA</State> |
9 | <Phone>(408) 245-7760</Phone> |
10 | <Latitude>37.388537</Latitude> |
11 | <Longitude>-122.003972</Longitude> |
12 | <Rating> |
13 | <AverageRating>3.5</AverageRating> |
14 | <TotalRatings>5</TotalRatings> |
15 | <TotalReviews>5</TotalReviews> |
16 | <LastReviewDate>1161495667</LastReviewDate> |
17 | </Rating> |
18 | <Distance>0.93</Distance> |
19 | <Url>http://local.yahoo.com/details?id=21332021&stx=pizza&csz=Sunnyvale+CA&ed=6tiAL6160Sx1XVIEu1zIWPu6fD8rJDV4.offJLNUTb1Ri2Q.R5oLTYvDCz8YmzivI7Bz0gfrpw--</Url> |
20 | <ClickUrl>http://local.yahoo.com/details?id=21332021&stx=pizza&csz=Sunnyvale+CA&ed=6tiAL6160Sx1XVIEu1zIWPu6fD8rJDV4.offJLNUTb1Ri2Q.R5oLTYvDCz8YmzivI7Bz0gfrpw--</ClickUrl> |
21 | <MapUrl>http://maps.yahoo.com/maps_result?name=Pizza+Depot&desc=4082457760&csz=Sunnyvale+CA&qty=9&cs=9&ed=6tiAL6160Sx1XVIEu1zIWPu6fD8rJDV4.offJLNUTb1Ri2Q.R5oLTYvDCz8YmzivI7Bz0gfrpw--&gid1=21332021</MapUrl> |
22 | <BusinessUrl>http://pizza-depot.com/</BusinessUrl> |
23 | <BusinessClickUrl>http://pizza-depot.com/</BusinessClickUrl> |
24 | </Result> |
25 | ... |
26 | </ResultSet> |
view plain | print | ? |
CSS:
1 | /* No custom CSS. */ |
view plain | print | ? |
Markup:
1 | <div id="localxml"></div> |
view plain | print | ? |
JavaScript:
1 | YAHOO.util.Event.addListener(window, "load", function() { |
2 | YAHOO.example.Local_XML = new function() { |
3 | this.connectionCallback = { |
4 | success: function(o) { |
5 | var xmlDoc = o.responseXML; |
6 | |
7 | var myColumnDefs = [ |
8 | {key:"Title", label:"Name", sortable:true, formatter:this.formatUrl}, |
9 | {key:"Phone"}, |
10 | {key:"City"}, |
11 | {key:"AverageRating", label:"Rating",formatter:YAHOO.widget.DataTable.formatNumber, sortable:true} |
12 | ]; |
13 | |
14 | this.myDataSource = new YAHOO.util.DataSource(xmlDoc); |
15 | this.myDataSource.responseType = YAHOO.util.DataSource.TYPE_XML; |
16 | this.myDataSource.responseSchema = { |
17 | resultNode: "Result", |
18 | fields: ["Title","Phone","City",{key:"AverageRating",parser:YAHOO.util.DataSource.parseNumber},"ClickUrl"] |
19 | }; |
20 | |
21 | this.myDataTable = new YAHOO.widget.DataTable("localxml", myColumnDefs, this.myDataSource); |
22 | |
23 | }, |
24 | failure: function(o) { |
25 | |
26 | } |
27 | }; |
28 | |
29 | this.getXML = YAHOO.util.Connect.asyncRequest("GET", |
30 | "assets/php/ylocal_proxy.php?query=pizza&zip=94089&results=10", |
31 | this.connectionCallback); |
32 | }; |
33 | }); |
view plain | print | ? |
Note: Logging and debugging is currently turned off for this example.
Copyright © 2008 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Copyright Policy - Job Openings