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