YUI recommends YUI 3.
YUI 2 has been deprecated since 2011. This site acts as an archive for files and documentation.
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 |
---|---|---|
Loading... | ||
1 | At the tone the time will be: | 12:22:48 PM |
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:
1 | YAHOO.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 | ? |
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.
Note: Logging and debugging is currently turned off for this example.
Copyright © 2011 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Copyright Policy - Job Openings