Yahoo! Developer Network Home - Help

YDN Site Search

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

# DataTable Control (beta): 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:YAHOO.util.DataSource.parseNumber},"ClickUrl"] }; this.myDataTable = new YAHOO.widget.DataTable("xml", myColumnDefs, this.myDataSource, {initialRequest:"query=pizza&zip=94089&results=10"}); }; });

### YUI Logger Output:

Note: Logging and debugging is currently turned off for this example.

Reload with logging
and debugging enabled.

### DataTable Control (beta) Examples:

- Basic Example
- Progressive Enhancement
- Custom Cell Formatting
- Nested Headers
- JSON Data Over XHR
- XML Data Over XHR With POST
- Textual Data Over XHR
- Local XML Data
- Adding and Deleting Rows
- Client-side Pagination
- Client-side Sorting
- Server-side Pagination
- Server-side Sorting
- Server-side Pagination and Sorting, with Browser History Manager
- XY-scrolling, Y-scrolling, and X-scrolling
- Row Selection
- Cell Selection
- Inline Cell Editing
- Context Menu Integration
- Showing, Hiding, and Reordering Columns.
- Highlighting Cells, Rows, or Columns
- Complex Example of Multiple Features
- Datatable with Autocomplete
- Skinning Model
- Configuring the Paginator
- Complex Application (included with examples for Layout Manager (beta))

### More DataTable Control (beta) Resources:

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

Copyright © 2008 Yahoo! Inc. All rights reserved.

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