YUI Library Home

Site Search (YDN & YUIBlog):

# YUI Library Examples: DataTable Control: Polling the DataSource

# DataTable Control: Polling the DataSource

This DataTable polls for data from its DataSource every 5 seconds. Due to browser limitations, implementers should use this feature to replace existing data, rather than continuously add data to the page.

View example in new window.

## Sample Code for this Example

Data:

[{ count:n, description:"At the tone the time will be: ", time: "[hh]:[mm]:[ss] [AM|PM]") }]

Markup:

<div id="polling"></div>

JavaScript:

YAHOO.util.Event.addListener(window, "load", function() { YAHOO.example.Polling = function() { var counter = 0; var dataIncrementer = function() { counter++; return [{ count:counter, description:"At the tone the time will be: ", time: YAHOO.util.Date.format(new Date(), {format:"%I:%M:%S %p"}) }] }; var myColumnDefs = [ {key: "count"}, {key: "description"}, {key: "time"} ]; var myDataSource = new YAHOO.util.DataSource(dataIncrementer); myDataSource.responseType = YAHOO.util.DataSource.TYPE_JSARRAY; myDataSource.responseSchema = { fields: ["count", "description", "time"] }; var myDataTable = new YAHOO.widget.DataTable("polling", myColumnDefs, myDataSource); // Set up polling var myCallback = { success: myDataTable.onDataReturnInitializeTable, failure: function() { YAHOO.log("Polling failure", "error"); }, scope: myDataTable } myDataSource.setInterval(5000, null, myCallback) return { oDS: myDataSource, oDT: myDataTable }; }(); });

## 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 © 2009 Yahoo! Inc. All rights reserved.

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