source: Dev/trunk/src/client/dojox/wire/demos/TableContainer.js @ 483

Last change on this file since 483 was 483, checked in by hendrikvanantwerpen, 11 years ago

Added Dojo 1.9.3 release.

File size: 2.0 KB
Line 
1dojo.provide("dojox.wire.demos.TableContainer");
2
3dojo.require("dojo.parser");
4dojo.require("dijit._Widget");
5dojo.require("dijit._Templated");
6
7dojo.declare("dojox.wire.demos.TableContainer", [ dijit._Widget, dijit._Templated, dijit._Container ], {
8        // summary:
9        //              Extremely simple 'widget' that is a table generator with an addRow function that takes an array
10        //              as the row to add, where each entry is a cell in the row.  This demo widget is for use with the
11        //              wire demos.
12
13        templateString: "<table class='tablecontainer'><tbody dojoAttachPoint='tableContainer'></tbody></table>",
14        rowCount: 0,
15        headers: "",
16        addRow: function(array){
17                // summary:
18                //              Function to add in a new row from the elements in the array map to cells in the row.
19                // array:
20                //              Array of row values to add.
21                try{
22                        var row = document.createElement("tr");
23                        if((this.rowCount%2) === 0){
24                                dojo.addClass(row, "alternate");
25                        }
26                        this.rowCount++;
27                        for(var i in array){
28                                var cell = document.createElement("td");
29                                var text = document.createTextNode(array[i]);
30                                cell.appendChild(text);
31                                row.appendChild(cell);
32                               
33                        }
34                        this.tableContainer.appendChild(row);
35                }catch(e){ console.debug(e); }
36        },
37
38        clearTable: function(){
39                // summary:
40                //              Function to clear all the current rows in the table, except for the header.
41
42                //Always leave the first row, which is the table header.
43                while(this.tableContainer.firstChild.nextSibling){
44                        this.tableContainer.removeChild(this.tableContainer.firstChild.nextSibling);
45                }
46                this.rowCount = 0;
47        },
48
49        postCreate: function(){
50                // summary:
51                //              Widget lifecycle function to handle generation of the header elements in the table.
52                var headers = this.headers.split(",");
53                var tr = document.createElement("tr");
54                for(i in headers){
55                       
56                        var header = headers[i];
57                        var th = document.createElement("th");
58                        var text = document.createTextNode(header);
59                        th.appendChild(text);
60                        tr.appendChild(th);
61                }
62                this.tableContainer.appendChild(tr);
63        }
64});
Note: See TracBrowser for help on using the repository browser.