YUI Library Home

Site Search (YDN & YUIBlog):

# YUI Library Examples: DataTable Control: XML Data Over XHR With POST

# DataTable Control: XML Data Over XHR With POST

This examples makes a POST query to the Yahoo! Local webservice to populate a DataTable.

View example in new window.

## Sample Code for this Example

Data:

<?xml version="1.0"?> <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="501" totalResultsReturned="10" firstResultPosition="1"> <ResultSetMapUrl>http://maps.yahoo.com/broadband/?q1=Sunnyvale%2C+CA+94089&tt=pizza&tp=1</ResultSetMapUrl> <Result> <Title>Giovannis Pizzeria</Title> <Address>1127 N Lawrence Expy</Address> <City>Sunnyvale</City> <State>CA</State> <Phone>(408) 734-4221</Phone> <Latitude>37.396953</Latitude> <Longitude>-121.995986</Longitude> <Rating> <AverageRating>4</AverageRating> <TotalRatings>51</TotalRatings> <TotalReviews>33</TotalReviews> <LastReviewDate>1191207644</LastReviewDate> </Rating> <Distance>0.62</Distance> <Url>http://local.yahoo.com/details?id=21341983&stx=pizza&csz=Sunnyvale+CA&ed=kYc.Ba160SxZddWADEWWMRsGo0KgZ6X22_QAgTZxq3OdfrVCfCdLU9mvvJeybt8XpDhMC58HjElJAiWi</Url> <ClickUrl>http://local.yahoo.com/details?id=21341983&stx=pizza&csz=Sunnyvale+CA&ed=kYc.Ba160SxZddWADEWWMRsGo0KgZ6X22_QAgTZxq3OdfrVCfCdLU9mvvJeybt8XpDhMC58HjElJAiWi</ClickUrl> <MapUrl>http://maps.yahoo.com/maps_result?name=Giovannis+Pizzeria&desc=4087344221&csz=Sunnyvale+CA&qty=9&cs=9&ed=kYc.Ba160SxZddWADEWWMRsGo0KgZ6X22_QAgTZxq3OdfrVCfCdLU9mvvJeybt8XpDhMC58HjElJAiWi&gid1=21341983</MapUrl> <BusinessUrl></BusinessUrl> <BusinessClickUrl></BusinessClickUrl> </Result> ... </ResultSet>

CSS:

/* No custom CSS. */

Markup:

<div id="xml"></div>

JavaScript:

YAHOO.util.Event.addListener(window, "load", function() { YAHOO.example.XHR_XML = new function() { this.formatUrl = function(elCell, oRecord, oColumn, sData) { elCell.innerHTML = "<a href='" + oRecord.getData("ClickUrl") + "' target='_blank'>" + sData + "</a>"; }; var myColumnDefs = [ {key:"Title", label:"Name", sortable:true, formatter:this.formatUrl}, {key:"Phone"}, {key:"City"}, {key:"AverageRating", label:"Rating",formatter:YAHOO.widget.DataTable.formatNumber, sortable:true} ]; this.myDataSource = new YAHOO.util.DataSource("assets/php/ylocal_proxy.php?"); this.myDataSource.connMethodPost = true; this.myDataSource.responseType = YAHOO.util.DataSource.TYPE_XML; this.myDataSource.responseSchema = { resultNode: "Result", fields: ["Title","Phone","City",{key:"AverageRating",parser:"number"},"ClickUrl"] }; this.myDataTable = new YAHOO.widget.DataTable("xml", myColumnDefs, this.myDataSource, {initialRequest:"query=pizza&zip=94089&results=10"}); }; });

## Configuration for This Example

You can load the necessary JavaScript and CSS for this example from Yahoo's servers. Click here to load the YUI Dependency Configurator with all of this example's dependencies preconfigured.

### YUI Logger Output:

Note: You are viewing this example in debug mode with logging enabled. This can significantly slow performance.

Reload with logging
and debugging disabled.

### DataTable Control Examples:

- Basic Example
- Progressive Enhancement
- Custom Cell Formatting
- Conditional row coloring
- Nested Headers
- JSON Data Over XHR
- XML Data Over XHR With POST
- XML Data with XPath
- Textual Data Over XHR
- Polling the DataSource
- Adding, Updating, and Deleting Rows
- Client-side Pagination
- Client-side Sorting
- Server-side Pagination and Sorting for Dynamic Data
- Integrating Browser History Manager with Server-side Pagination and Sorting
- XY-scrolling, Y-scrolling, and X-scrolling
- Row Selection
- Cell Selection
- Inline Cell Editing
- Showing, Hiding, and Reordering Columns.
- Highlighting Cells, Rows, or Columns
- Reorder Rows with Drag and Drop
- Row Expansion
- Context Menu Integration
- Configuring the Paginator (included with examples for Paginator)
- TabView Integration
- Complex Example of Multiple Features
- Client-side Filtering of Local Data
- Filtering of Dynamic Data
- Datatable with Autocomplete
- Skinning Model
- Ratings (included with examples for ProgressBar Control)
- YQLDataSource (included with examples for DataSource Utility)
- Complex Application (included with examples for Layout Manager)

### More DataTable Control Resources:

- User's Guide (external)
- API Documentation
- Cheat Sheet PDF (external)

Copyright © 2010 Yahoo! Inc. All rights reserved.

Privacy Policy - Terms of Service - Copyright Policy - Job Openings