summaryrefslogtreecommitdiff
path: root/includes/js/dojox/data/demos/demo_DataDemoTable.html
blob: 09761b96f29453785cc385799b1fe352e7350851 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
        "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
	<title>Dojo Visual Loader Test</title>
	<style type="text/css">
		@import "../../../dojo/resources/dojo.css";
		@import "../../../dijit/themes/tundra/tundra.css";
		@import "../../../dijit/themes/dijit.css";
		@import "../../../dijit/tests/css/dijitTests.css"; 

		.oddRow { background-color: #f2f5f9; }
		.population { text-align: right; }
	</style>

	<script type="text/javascript" src="../../../dojo/dojo.js" 
		djConfig="isDebug: false, parseOnLoad: true"></script>
	<script type="text/javascript">
		dojo.require("dijit.dijit");
		dojo.require("dojo.parser");
		dojo.require("dijit.Declaration");
		dojo.require("dojo.data.ItemFileReadStore");
		dojo.require("dojox.data.FlickrStore");
	</script>
</head>
<body class="tundra">
	<span dojoType="dojo.data.ItemFileReadStore" 
		jsId="continentStore"
		url="../../../dijit/tests/_data/countries.json"></span>
	<span dojoType="dojox.data.FlickrStore" jsId="flickrStore"></span>


	<h1 class="testTitle">Dojox Data Demo Table</h1>

	<table dojoType="dijit.Declaration" 
		widgetClass="demo.Table" class="dojoTabular" 
		defaults="{ store: null, query: { query: { name: '*' } }, columns: [ { name: 'Name', attribute: 'name' } ] }">
		<thead dojoAttachPoint="head">
			<tr dojoAttachPoint="headRow"></tr>
		</thead>
		<tbody dojoAttachPoint="body">
			<tr dojoAttachPoint="row">
			</tr>
		</tbody>

		<script type="dojo/method">
			dojo.forEach(this.columns, function(item, idx){
				var icn = item.className||"";
				// add a header for each column
				var tth = document.createElement("th");
				tth.innerHTML = item.name;
				tth.className = icn;
				dojo.connect(tth, "onclick", dojo.hitch(this, "onSort", idx));
				this.headRow.appendChild(tth);

				// and fill in the column cell in the template row
				this.row.appendChild(document.createElement("td"));
				this.row.lastChild.className = icn;
			}, this);
			this.runQuery();
		</script>
		<script type="dojo/method" event="onSort" args="index">
			var ca = this.columns[index].attribute;
			var qs = this.query.sort;
			// clobber an existing sort arrow
			dojo.query("> th", this.headRow).style("background", "").style("paddingRight", "");
			if(qs && qs[0].attribute == ca){
				qs[0].descending = !qs[0].descending;
			}else{
				this.query.sort = [{
					attribute: ca,
					descending: false
				}];
			}
			var th = dojo.query("> th", this.headRow)[index];
			th.style.paddingRight = "16px"; // space for the sort arrow
			th.style.background = "url(\""+dojo.moduleUrl("dijit", "themes/tundra/images/arrow"+(this.query.sort[0].descending ? "Up" : "Down")+((dojo.isIE == 6) ? ".gif" : ".png")) + "\") no-repeat 98% 4px";
			this.runQuery();
		</script>
		<script type="dojo/method" event="runQuery">
			this.query.onBegin = dojo.hitch(this, function(){ dojo.query("tr", this.body).orphan(); });
			this.query.onItem = dojo.hitch(this, "onItem");
			this.query.onComplete = dojo.hitch(this, function(){
				dojo.query("tr:nth-child(odd)", this.body).addClass("oddRow");
				dojo.query("tr:nth-child(even)", this.body).removeClass("oddRow");
			});
			this.store.fetch(this.query);
		</script>
		<script type="dojo/method" event="onItem" args="item">
			var tr = this.row.cloneNode(true);
			dojo.query("td", tr).forEach(function(n, i, a){
				var tc = this.columns[i];
				var tv = this.store.getValue(item, tc.attribute)||"";
				if(tc.format){ tv = tc.format(tv, item, this.store); }
				n.innerHTML = tv;
			}, this);
			this.body.appendChild(tr);
		</script>
	</table>

	<span dojoType="demo.Table" store="continentStore"
		query="{ query: { type: 'country' }, sort: [ { attribute: 'name', descending: true } ]  }" 
		id="foo">
		<script type="dojo/method" event="preamble">
			this.columns = [
				{ name: "Name", attribute: "name" },
				{	name: 		"Population",
					attribute:	"population",
					className:	"population"
				}
			];
		</script>
	</span>
	<span dojoType="demo.Table" store="continentStore"
		query="{ query: { name: 'A*' } }"></span>
	<span dojoType="demo.Table" store="flickrStore"
		query="{ query: { tags: '3dny' } }">
		<script type="dojo/method" event="preamble">
			this.columns = [
				{	name: "", attribute: "imageUrlSmall", 
					format: function(value, item, store){
						return (value.length) ? "<img src='"+value+"'>" : "";
					}
				},
				{ name: "Title", attribute: "title" }
			];
		</script>
	</span>
</body>
</html>