Yahoo! Developer Network Home - Help

YDN Site Search

# YUI Library Examples: DataTable Control (beta): Textual Data Over XHR

# DataTable Control (beta): Textual Data Over XHR

This example demonstrates how to populate a DataTable with delimited text data over XHR. In the second instance, the data includes header data as the first row, which is parsed out with a custom implementation of the DataSource method doBeforeCallback().

View example in new window.

## Sample Code for this Example

Data (standard):

Domino's Pizza|615 Caliente Dr|Sunnyvale|(408) 732-3030|4|http://local.yahoo.com/details?id=21335892&stx=pizza&csz=Sunnyvale+CA&ed=17rS8q160Sy5Htog0TF1m1atNv01Iz7ySeGEMtCL4dJsf1ku0nhziD2qN5XcnHlJtDS4IydIbA-- ...

Data (with headers):

Restaurant|Location|Town|Telephone|Stars|Website Domino's Pizza|615 Caliente Dr|Sunnyvale|(408) 732-3030|4|http://local.yahoo.com/details?id=21335892&stx=pizza&csz=Sunnyvale+CA&ed=17rS8q160Sy5Htog0TF1m1atNv01Iz7ySeGEMtCL4dJsf1ku0nhziD2qN5XcnHlJtDS4IydIbA-- ...

CSS:

/* No custom CSS. */

Markup:

<div id="text"></div> <div id="textWithHeaderData"></div>

JavaScript:

YAHOO.util.Event.addListener(window, "load", function() { YAHOO.example.XHR_Text = new function() { this.formatUrl = function(elCell, oRecord, oColumn, sData) { elCell.innerHTML = "<a href='" + oRecord.getData("Url") + "' target='_blank'>" + sData + "</a>"; }; var myColumnDefs = [ {key:"Name", sortable:true, formatter:this.formatUrl}, {key:"Phone"}, {key:"City"}, {key:"Rating", formatter:YAHOO.widget.DataTable.formatNumber, sortable:true} ]; this.myDataSource = new YAHOO.util.DataSource("assets/php/text_proxy.txt?"); this.myDataSource.responseType = YAHOO.util.DataSource.TYPE_TEXT; this.myDataSource.responseSchema = { recordDelim: "\n", fieldDelim: "|", fields: ["Name","Address","City","Phone",{key:"Rating",parser:YAHOO.util.DataSource.parseNumber},"Url"] }; this.myDataTable = new YAHOO.widget.DataTable("text", myColumnDefs, this.myDataSource, {caption:"Example: Textual Data Over XHR"}); var moreColumnDefs = [ {key:"Restaurant", sortable:true, formatter:this.formatUrl}, {key:"Location"}, {key:"Town"}, {key:"Stars", formatter:YAHOO.widget.DataTable.formatNumber, sortable:true} ]; this.anotherDataSource = new YAHOO.util.DataSource("assets/php/text_with_headers_proxy.txt?"); this.anotherDataSource.responseType = YAHOO.util.DataSource.TYPE_TEXT; this.anotherDataSource.responseSchema = { recordDelim: "\n", fieldDelim: "|", fields: ["Restaurant","Location","Town","Telephone",{key:"Stars",parser:YAHOO.util.DataSource.parseNumber},"Website"] }; // Upgrade note: As of 2.5.0, the second argument is the full type-converted // response from the live data, and not the unconverted raw response this.anotherDataSource.doBeforeCallback = function(oRequest, oFullResponse, oParsedResponse) { // Remove the first result (i.e., the headers); oParsedResponse.results.shift(); return oParsedResponse; }; this.anotherDataTable = new YAHOO.widget.DataTable("textWithHeaderData", moreColumnDefs, this.anotherDataSource, {caption:"Example: First Record Holds Header Data"}); }; });

### 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
- 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 and Hiding 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