YUI Library Home

Site Search (YDN & YUIBlog):

# YUI Library Examples: DataTable Control: Progressive Enhancement

# DataTable Control: Progressive Enhancement

This example creates a DataTable instance based on markup that already exists on the page. By progressively enhancing markup with higher order functionality, users who do not have JavaScript enabled are still able to view the page's content and experience core functionality.

In this example's code, note that we listen for the window "load" event before calling our function to be sure that the original table markup is fully rendered and available as a DataSource source for our DataTable instance.

View example in new window.

Due Date | Account Number | Quantity | Amount Due
--- | --- | --- | ---
1/23/1999 | 29e8548592d8c82 | 12 | $150.00
5/19/1999 | 83849 | 8 | $60.00
8/9/1999 | 11348 | 1 | $34.99
1/23/2000 | 29e8548592d8c82 | 10 | $1.00
4/28/2000 | 37892857482836437378273 | 123 | $33.32
1/23/2001 | 83849 | 5 | $15.00
9/30/2001 | 224747 | 14 | $56.78

## Sample Code for this Example

Data:

/* Data is derived from the HTML TABLE element. */

CSS:

/* No custom CSS. */

Markup:

<div id="markup"> <table id="accounts"> <thead> <tr> <th>Due Date</th> <th>Account Number</th> <th>Quantity</th> <th>Amount Due</th> </tr> </thead> <tbody> <tr> <td>1/23/1999</td> <td>29e8548592d8c82</td> <td>12</td> <td>$150.00</td> </tr> <tr> <td>5/19/1999</td> <td>83849</td> <td>8</td> <td>$60.00</td> </tr> <tr> <td>8/9/1999</td> <td>11348</td> <td>1</td> <td>$34.99</td> </tr> <tr> <td>1/23/2000</td> <td>29e8548592d8c82</td> <td>10</td> <td>$1.00</td> </tr> <tr> <td>4/28/2000</td> <td>37892857482836437378273</td> <td>123</td> <td>$33.32</td> </tr> <tr> <td>1/23/2001</td> <td>83849</td> <td>5</td> <td>$15.00</td> </tr> <tr> <td>9/30/2001</td> <td>224747</td> <td>14</td> <td>$56.78</td> </tr> </tbody> </table> </div>

JavaScript:

YAHOO.util.Event.addListener(window, "load", function() { YAHOO.example.EnhanceFromMarkup = new function() { var myColumnDefs = [ {key:"due",label:"Due Date",formatter:YAHOO.widget.DataTable.formatDate,sortable:true}, {key:"account",label:"Account Number", sortable:true}, {key:"quantity",label:"Quantity",formatter:YAHOO.widget.DataTable.formatNumber,sortable:true}, {key:"amount",label:"Amount Due",formatter:YAHOO.widget.DataTable.formatCurrency,sortable:true} ]; this.parseNumberFromCurrency = function(sString) { // Remove dollar sign and make it a float return parseFloat(sString.substring(1)); }; this.myDataSource = new YAHOO.util.DataSource(YAHOO.util.Dom.get("accounts")); this.myDataSource.responseType = YAHOO.util.DataSource.TYPE_HTMLTABLE; this.myDataSource.responseSchema = { fields: [{key:"due", parser:"date"}, {key:"account"}, {key:"quantity", parser:"number"}, {key:"amount", parser:this.parseNumberFromCurrency} // point to a custom parser ] }; this.myDataTable = new YAHOO.widget.DataTable("markup", myColumnDefs, this.myDataSource, {caption:"Example: Progressively Enhanced Table from Markup", sortedBy:{key:"due",dir:"asc"}} ); }; });

## 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: Logging and debugging is currently turned off for this example.

Reload with logging
and debugging enabled.

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