aboutsummaryrefslogtreecommitdiff
path: root/includes/js/dojox/grid/tests/test_expand.html
blob: 220c2a82207459793495e8c950154dd094f364e2 (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
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<title>Test dojox.Grid Expand Rows</title>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8"></meta>
	<style type="text/css">
		@import "../_grid/Grid.css";
		body {
			font-size: 0.9em;
			font-family: Geneva, Arial, Helvetica, sans-serif;
		}
		.heading {
			font-weight: bold;
			padding-bottom: 0.25em;
		}
		
		.bigHello {
			height: 110px;
			line-height: 110px;
			text-align: center;
			font-weight: bold;
			font-size: 30px;
		}	
				
		#grid { 
			border: 1px solid #333;
			height: 30em;
		}
	</style>
	<script type="text/javascript" src="../../../dojo/dojo.js" djConfig="isDebug:false, parseOnLoad: true"></script>
	<script type="text/javascript">
		dojo.require("dojox.grid.Grid");
		dojo.require("dojo.parser");
	</script>
	<script type="text/javascript">
		// grid structure
		// a grid view is a group of columns
		
		// a special view providing selection feedback
		var rowBar = {type: 'dojox.GridRowView', width: '20px' };
		
		// inRow is an array of subRows. we hide the summary subRow except for every nth row
		function onBeforeRow(inDataIndex, inRow) {
			inRow[1].hidden = (!this.grid || !this.grid.expandedRows || !this.grid.expandedRows[inDataIndex]);
		}
		
		var view = {
			onBeforeRow: onBeforeRow,
			cells: [
				[
					{ name: 'Whatever', width: 4.5, get: getCheck, styles: 'text-align: center;' },
					{name: 'Column 0'},
					{name: 'Column 1'},
					{name: 'Column 2'},
					{name: 'Column 3'},
					{name: 'Column 4'}
				],
				[ { name: 'Detail', colSpan: 6, get: getDetail } ]
			]
		};
		
		// a grid structure is an array of views.
		var structure = [ rowBar, view ];
		
		// get can return data for each cell of the grid
		function get(inRowIndex) {
			return [this.index, inRowIndex].join(', ');
		}
		
		function getDetail(inRowIndex) {
			if (this.grid.expandedRows[inRowIndex]) {
				var n = (inRowIndex % 2);
				switch (n) {
					case 0:
						return 'Hello World!';
					default:
						return '<div class="bigHello">Hello World!</div>';
				}
			} else
				return '';
		}
		
		function toggle(inIndex, inShow) {
			grid.expandedRows[inIndex] = inShow;
			grid.updateRow(inIndex);
		}
		
		function getCheck(inRowIndex) {
			if (!this.grid.expandedRows)
				this.grid.expandedRows = [ ];
			var image = (this.grid.expandedRows[inRowIndex] ? 'open.gif' : 'closed.gif');
			var show = (this.grid.expandedRows[inRowIndex] ? 'false' : 'true')
			return '<img src="images/' + image + '" onclick="toggle(' + inRowIndex + ', ' + show + ')" height="11" width="11">';
		}

	dojo.addOnLoad(function() {
		window["grid"] = dijit.byId("grid");
	});
</script>
</head>
<body>
<div class="heading">dojox.Grid Expand Row Example</div>

<div id="grid" dojoType="dojox.VirtualGrid" get="get" structure="structure" rowCount="100000" autoWidth="true"></div>

</body>
</html>