YUI Library Home

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.

count
description
time
1
At the tone the time will be:
10:55:31 AM

Sample Code for this Example

Data:

1[{ 
2    count:n,  
3    description:"At the tone the time will be: ",  
4    time: "[hh]:[mm]:[ss] [AM|PM]") 
5}] 
view plain | print | ?

Markup:

1<div id="polling"></div> 
view plain | print | ?

JavaScript:

1YAHOO.util.Event.addListener(window, "load"function() { 
2    YAHOO.example.Polling = function() { 
3        var counter = 0; 
4        var dataIncrementer = function() { 
5            counter++; 
6            return [{ 
7                count:counter,  
8                description:"At the tone the time will be: ",  
9                time: YAHOO.util.Date.format(new Date(), {format:"%I:%M:%S %p"}) 
10            }] 
11        }; 
12 
13        var myColumnDefs = [ 
14            {key: "count"}, 
15            {key: "description"}, 
16            {key: "time"
17        ]; 
18 
19        var myDataSource = new YAHOO.util.DataSource(dataIncrementer); 
20        myDataSource.responseType = YAHOO.util.DataSource.TYPE_JSARRAY; 
21        myDataSource.responseSchema = { 
22            fields: ["count""description""time"
23        }; 
24 
25        var myDataTable = new YAHOO.widget.DataTable("polling"
26                myColumnDefs, myDataSource); 
27                 
28        // Set up polling 
29        var myCallback = { 
30            success: myDataTable.onDataReturnInitializeTable, 
31            failure: function() { 
32                YAHOO.log("Polling failure""error"); 
33            }, 
34            scope: myDataTable 
35        } 
36        myDataSource.setInterval(5000, null, myCallback) 
37                 
38        return { 
39            oDS: myDataSource, 
40            oDT: myDataTable 
41        }; 
42    }(); 
43}); 
view plain | print | ?

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:

Logger Console

INFO 1722ms (+0) 10:55:31 AM:

DataTable instance yui-dt0

Post-render routine executed

INFO 1722ms (+5) 10:55:31 AM:

DataTable instance yui-dt0

DataTable rendered

INFO 1717ms (+0) 10:55:31 AM:

DataSource instance0

Enabling polling to live data for "null" at interval 5000

INFO 1717ms (+1) 10:55:31 AM:

DataTable instance yui-dt0

DataTable message hidden

INFO 1716ms (+0) 10:55:31 AM:

DataTable instance yui-dt0

DataTable rendering...

INFO 1716ms (+0) 10:55:31 AM:

RecordSet instance yui-rs0

Set 1 Record(s) at index 0

INFO 1716ms (+1) 10:55:31 AM:

DataSource instance0

Parsed array data is {results => [{time => 10:55:31 AM, description => At the tone the time will be: , count => 1}]}

INFO 1715ms (+0) 10:55:31 AM:

DataSource instance0

Received live data response for "null"

INFO 1715ms (+0) 10:55:31 AM:

DataSource instance0

Making connection to live data for "null"

INFO 1715ms (+1) 10:55:31 AM:

DataTable instance yui-dt0

DataTable showing message: Loading...

INFO 1714ms (+2) 10:55:31 AM:

DataTable instance yui-dt0

TH cells for 3 keys created

INFO 1712ms (+0) 10:55:31 AM:

RecordSet instance yui-rs0

RecordSet initialized

INFO 1712ms (+1) 10:55:31 AM:

ColumnSet instance yui-cs0

ColumnSet initialized

INFO 1711ms (+8) 10:55:31 AM:

DataSource instance0

DataSource initialized

INFO 1703ms (+1703) 10:55:31 AM:

LogReader instance0

LogReader initialized

INFO 0ms (+0) 10:55:29 AM:

global

Logger initialized

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

Reload with logging
and debugging disabled.

More DataTable Control Resources:

Copyright © 2009 Yahoo! Inc. All rights reserved.

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