summaryrefslogtreecommitdiff
path: root/js/dojo/dojox/data/demos/demo_QueryReadStore_grid.html
blob: 7035ebde1118b2ebf5e024b8992e8d905c96e2da (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
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
	<title>Dojox QueryReadStore+grid Demo</title>
	<style type="text/css">
		@import "../../../dijit/themes/tundra/tundra.css";
		@import "../../../dojo/resources/dojo.css";
		@import "../../../dijit/tests/css/dijitTests.css";
		/* BE SURE TO NEVER FORGET IMPORTING THE GRID's CSS, or you will wonder why the 
		   grid looks so strange (or even think that it doesnt work) */
		@import "../../../dojox/grid/resources/tundraGrid.css";
	</style>

	<script type="text/javascript" src="../../../dojo/dojo.js" djConfig="isDebug:true, parseOnLoad: true, useCommentedJson: true"></script>
	<script type="text/javascript">
		dojo.require("dojox.grid.DataGrid");
		dojo.require("dojox.data.QueryReadStore");
		dojo.require("dojo.parser"); // scan page for widgets and instantiate them
		var gridLayout = [
			new dojox.grid.cells.RowIndex({ name: "row #", width: 5, styles: "text-align: right;" }),
			{
				name: "id",
				field: "id",
				styles: "text-align:right;",
				width:5
			},
			{
				name: "Name",
				field: "name",
				width:20
				//formatter: rs.chunk.adminUser.grid.formatUser
			},
			{
				name: "Capital",
				field: "capital",
				width:20
				//formatter: rs.chunk.adminUser.grid.formatUser
			},
			{
				name: "Label",
				width:20,
				//styles: "text-align:right;",
				field: "label"
				//formatter: phpr.grid.formatDate
			},
			{
				name: "Abbrev.",
				width:5,
				//styles: "text-align:right;",
				field: "abbreviation"
				//formatter: phpr.grid.formatDate
			}
		];
		// Connect the store AFTER the page is loaded, since we can only access
		// the widget then, since it will be created just before dojo.addOnLoad() is called.
		var store = null;
		dojo.addOnLoad(function() {
			store = new dojox.data.QueryReadStore({
				url:"../tests/stores/QueryReadStore.php",
				requestMethod:"post"
			});
			grid1.setStore(store);
			grid1.setStructure(gridLayout);
		});
		
		var lastSearchValue = "";
		function doSearch(el) {
			if (el.value!=lastSearchValue) {
				lastSearchValue = el.value;
				grid1.filter({name:el.value});
				grid2.filter({name:el.value});
			}
		}
	</script>
</head>
<body class="tundra">

	<h1 class="testTitle">Dojox QueryReadStore + Grid demo - paging, sortable and filterable all server-side</h1>
 
	<h2>The grid is in HTML, store, etc. are JS, sorting is added by extending the model class</h2>
	<b>Capabilities:</b> load data from server, show data, paging (30 rows at a time), sort, filter<br />
	You can see that data are loaded upon demand by scrolling down in the grid below line #30,
	open FireBug and you see a server request being issued, to retreive another 30 rows/items.<br />
	<br /><br />
	<input type="text" onkeyup="doSearch(this)" />
	<div id="grid1" jsid="grid1" dojoType="dojox.grid.DataGrid" query="{ name: '*' }" rowsPerPage="30" style="height:300px; width:800px;"></div>

	<h2>The store and grid are "generated" and connected in HTML, filtering is done via JS</h2>
	This store is by default sorted descending by name (not as the one above, which is ascending).
	<div dojoType="dojox.data.QueryReadStore"
		jsId="store2"
		url="../tests/stores/QueryReadStore.php"
		requestMethod="post"></div>
	<!--<div dojoType="dojox.grid._data.DojoData"
		jsId="model2"
		store="store2"
		sortFields="[{attribute: 'capital', descending: true}]"
		rowsPerPage="30"></div>-->
	<div dojoType="dojox.grid.DataGrid"
		id="grid2" jsid="grid2"
		store="store2"
		query="{ name: '*' }"
		rowsPerPage="30"
		structure="gridLayout"
		style="height:300px; width:800px;"></div>



</body>
</html>