aboutsummaryrefslogtreecommitdiff
path: root/includes/js/dojox/grid/tests/test_dojo_data_model_multiStores.html
blob: 46554e3514434cd157f14060aa70cb735138f883 (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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<title>dojox.Grid with Dojo.Data via binding.  Multiple Store implementations.</title>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8"></meta>
	<style type="text/css">
		@import "../../../dijit/themes/tundra/tundra.css";
		@import "../../../dojo/resources/dojo.css";
		@import "../../../dijit/tests/css/dijitTests.css";
		@import "../_grid/tundraGrid.css";
		
		#grid, #grid2, #grid3, #grid4, #grid5, #grid6{
			width: 65em;
			height: 25em;
			padding: 1px;
		}
	</style>
	<script type="text/javascript" src="../../../dojo/dojo.js" 
		djConfig="isDebug: true, debugAtAllCosts: false, parseOnLoad: true"></script>
	<script type="text/javascript">
		dojo.require("dojox.grid.Grid");
		dojo.require("dojo.data.ItemFileReadStore");
		dojo.require("dojox.data.CsvStore");
		dojo.require("dojox.data.XmlStore");
		dojo.require("dojox.data.FlickrStore");
		dojo.require("dojox.data.OpmlStore");
		dojo.require("dojox.data.HtmlStore");
		dojo.require("dojo.parser");
	</script>

	<script type="text/javascript">
		function getRow(inRowIndex){
			return ' ' + inRowIndex;
		}
		
		var formatHref = function(attribute, rowIndex) {
			model = dataModel4;
			if(!model)
				return "?";
			var value = model.getRow(rowIndex);
			if(value && value[attribute])
				return "<a href=\"" + value[attribute] + "\" target=\"_blank\">Image Link</a>";
			return "";
		}

		var layoutMovies = [
			// view 0
			{ type: 'dojox.GridRowView', width: '20px' },
			// view 1
			{ cells: [[{ name: "Row", get: getRow, width: 5}]], noscroll: true},
			// view 2
			{ cells: [[
				{ field: "Title", width: 'auto' },
				{ field: "Year", width: 5 },
				{ field: "Producer", width: 20 }
			]]}
		];
		
		var layoutCountries = [
			// view 0
			{ type: 'dojox.GridRowView', width: '20px' },
			// view 1
			{ cells: [[{ name: "Row", get: getRow, width: 5}]], noscroll: true},
			// view 2
			{ cells: [[
				{ field: 0, width: 'auto' },
				{ width: 8 }
			]]}
		];

		var layoutBooks = [
			// view 0
			{ type: 'dojox.GridRowView', width: '20px' },
			// view 1
			{ cells: [[{ name: "Row", get: getRow, width: 5}]], noscroll: true},
			// view 2
			{ cells: [[
				{ field: "title", width: 'auto' },
				{ field: "isbn", width: '8' }
			]]}
		];

		//Lay out the Flickr data so one column is a URL.  This makes use of the
		//get function of a cell.
		var layoutFlickrData = [
			// view 0
			{ type: 'dojox.GridRowView', width: '20px' },
			// view 1
			{ cells: [[{ name: "Row", get: getRow, width: 5}]], noscroll: true},
			// view 2
			{ cells: [[
				{ name: "Title", field: "title", width: 'auto' },
				{ name: "Image URL", field: "imageUrl", width: '15', get: dojo.partial(formatHref, "imageUrl")}
			]]}
		];

		var layoutOpmlData = [
			// view 0
			{ type: 'dojox.GridRowView', width: '20px' },
			// view 1
			{ cells: [[{ name: "Row", get: getRow, width: 5}]], noscroll: true},
			// view 2
			{ cells: [[
				{ name: 'Name', field: 'text', width: 'auto'},
				{ name: 'Type', field: 'type', width: '8' }
			]]}
		];

		var layoutHtmlTable = [
			// view 0
			{ type: 'dojox.GridRowView', width: '20px' },
			// view 1
			{ cells: [[{ name: "Row", get: getRow, width: 5}]], noscroll: true},
			// view 2
			{ cells: [[
				{ name: 'Column 1', field: 'Column 1', width: 'auto'},
				{ name: 'Column 2', field: 'Column 2', width: 'auto'},
				{ name: 'Column 3', field: 'Column 3', width: 'auto'},
				{ name: 'Column 4', field: 'Column 4', width: 'auto'}
			]]}
		];
	</script>
</head>
<body class="tundra">
	<h1>dojox.Grid using Dojo.Data stores via simple binding with multiple store implementations.</h1>
	<p>
		This page demonstrates the Grid can display data accessed by dojo.data implementing Datastores.  
		Each of the datastores used stores data in a different format, and as this test and demonstration
		page shows, the logic for rendering the data is virtually identical.  You define your source store,
		you define the model for accessing the data, which is ij this case the dojox.grid.data.DojoData model
		and then you define the layout, which maps the data attribute names to columns in the grid.  You can 
		even perform cusomization of what is displayed, as demonstrated in the dojox.data.FlickrStore layout.  
		The image url is displayed as a clickable link that opens a new page.
	</p>
	<p>
		The choice of stores used were ones that did not require back end services to function for sake of 
		simplicity.  There is no reason that dojox.data.QueryReadStore could not be used with grid as well,
		it just requires a back end service to send it the query results.
	</p>
	<p><b>Stores used:</b></p>
	<ul>
		<li>dojo.data.ItemFileReadStore</li>
		<li>dojox.data.CvsStore</li>
		<li>dojox.data.XmlStore</li>
		<li>dojox.data.FlickrStore</li>
		<li>dojox.data.OpmlStore</li>
		<li>dojox.data.HtmlTableStore</li>
	</ul>

	<h2>dojo.data.ItemFileReadStore:</h2>
	<i>Displays a list of countries through ItemFileReadStore format.</i>
	<span dojoType="dojo.data.ItemFileReadStore" 
		jsId="jsonStore" url="../../../dijit/tests/_data/countries.json">
	</span>
	<span dojoType="dojox.grid.data.DojoData" 
		jsId="dataModel" 
		rowsPerPage="20"
		store="jsonStore" 
		query="{ name : '*' }">
	</span>
	<div id="grid" dojoType="dojox.Grid" elasticView="2" 
		model="dataModel" structure="layoutCountries">
	</div>


	<h2>dojox.data.CsvStore:</h2>
	<i>Displays a list of movies that were stored in CSV format.</i>
	<span dojoType="dojox.data.CsvStore" 
		jsId="csvStore" url="support/movies.csv">
	</span>
	<span dojoType="dojox.grid.data.DojoData" 
		jsId="dataModel2"
		store="csvStore"
		rowsPerPage="5"
		query="{ Title: '*' }"
		clientSort="true">
	</span>
	<div id="grid2" dojoType="dojox.Grid" elasticView="2" 
		model="dataModel2" structure="layoutMovies">

	</div>

	<h2>dojox.data.XmlStore:</h2>
	<i>Displays a list of books that were stored in XML format.</i>
	<span dojoType="dojox.data.XmlStore" 
		jsId="xmlStore" url="support/books.xml">
	</span>
	<span dojoType="dojox.grid.data.DojoData" 
		jsId="dataModel3" 
		rowsPerPage="5"
		store="xmlStore" 
		query="{ title : '*' }">
	</span>
	<div id="grid3" dojoType="dojox.Grid" elasticView="2" 
		model="dataModel3" structure="layoutBooks">
	</div>


	<h2>dojox.data.FlickrStore:</h2>
	<i>Displays Flickr imformation on 3DNY (Dojo Developer Days, New York) from the flickr public photo feed, accessed via the FlickrStore dojo.data implementation.</i>
	<span dojoType="dojox.data.FlickrStore" 
		jsId="flickrStore">
	</span>
	<span dojoType="dojox.grid.data.DojoData" 
		jsId="dataModel4" 
		rowsPerPage="5"
		store="flickrStore" 
		query="{ tags : '3dny' }">
	</span>
	<div id="grid4" dojoType="dojox.Grid" elasticView="2" 
		model="dataModel4" structure="layoutFlickrData">
	</div>


	<h2>dojox.data.OpmlStore:</h2>
	<i>Scans an Opml based document for all items of type 'country'</i> 
	<span dojoType="dojox.data.OpmlStore" 
		jsId="opmlStore" url="support/geography.xml">
	</span>
	<span dojoType="dojox.grid.data.DojoData" 
		jsId="dataModel5" 
		rowsPerPage="5"
		store="opmlStore" 
		query="{ type : 'country' }"
		queryOptions="{deep: true}"
		sortFields="[ { attribute : 'text' } ]">
	</span>
	<div id="grid5" dojoType="dojox.Grid" elasticView="2" 
		model="dataModel5" structure="layoutOpmlData">
	</div>


	<h2>dojox.data.HtmlStore:</h2>
	<i>Loads the grid from an HTML Table.</i> 
	<span dojoType="dojox.data.HtmlStore" 
		jsId="htmlStore" dataId="tableExample">
	</span>
	<span dojoType="dojox.grid.data.DojoData" 
		jsId="dataModel6" 
		rowsPerPage="5"
		store="htmlStore" 
		query="{}">
	</span>
	<div id="grid6" dojoType="dojox.Grid" elasticView="2" 
		model="dataModel6" structure="layoutHtmlTable">
	</div>

	<!-- 
		Inline data table to be displayed bu the grid! 
		This is accessed via the dojox.data.HtmlTableStore
	-->
	<table id="tableExample" style="display: none;">
		<thead>
			<tr>
				<th>Column 1</th>
				<th>Column 2</th>
				<th>Column 3</th>
				<th>Column 4</th>
			</tr>
		</thead>
		<tbody>
			<tr>
				<td>This</td>
				<td>is</td>
				<td></td>
				<td>empty in column 3</td>
			</tr>
			<tr>
				<td>This</td>
				<td>is</td>
				<td>a</td>
				<td>value</td>
			</tr>
			<tr>
				<td>Who?</td>
				<td>What?</td>
				<td>When?</td>
				<td>Where?</td>
			</tr>
			<tr>
				<td>She</td>
				<td>sells</td>
				<td>sea</td>
				<td>shells</td>
			</tr>
		</tbody>
	</table>
</body>
</html>