YUI recommends YUI3.

YUI 2 has been deprecated since 2011. This site acts as an archive for files and documentation.

This documentation is no longer maintained.

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.

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

Copyright © 2013 Yahoo! Inc. All rights reserved.

Privacy Policy - Copyright Policy - Job Openings