aboutsummaryrefslogtreecommitdiff
path: root/includes/js/dojox/data/demos/demo_QueryReadStore_grid.html
blob: 3f7db7e6929332906bc73ce634363dffc831af4c (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
<!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 hell the grid looks so strange (or even think that it doesnt work) */
		@import "../../../dojox/grid/_grid/tundraGrid.css";
	</style>

	<script type="text/javascript" src="../../../dojo/dojo.js" djConfig="isDebug:true, parseOnLoad: true"></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, model, 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" dojoType="dojox.Grid" 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" id="grid2"
		model="model2"
		structure="gridLayout"
		style="height:300px; width:800px;"></div>

	<script type="text/javascript">
		dojo.require("dojo.parser"); // scan page for widgets and instantiate them
		dojo.require("dojox.grid.Grid");
		dojo.require("dojox.grid._data.model"); // dojox.grid.data.DojoData is in there
		dojo.require("dojox.data.QueryReadStore");
		var gridLayout = [
			{
				cells: [[
					{
						name: "row #",
						width:5,
						styles: "text-align:right;",
						get:function(inRowIndex) { return inRowIndex+1;} // this auto generates a row num
					} 
					,{
						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 model and 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 grid = null;
		dojo.addOnLoad(function() {
			// Instanciate the store, pass it to the model, connect them to the grid and add the layout ... just some hand work :-)
			//var store = new dojox.data.QueryReadStore({url:"../tests/stores/QueryReadStore.php", requestMethod:"post", doClientPaging:false});
			var store = new dojox.data.QueryReadStore({
				url:"../tests/stores/QueryReadStore.php",
				requestMethod:"post"
			});
			var model = new dojox.grid.data.DojoData(null, null, {
				store:store,
				rowsPerPage:30,
				sortFields:[{attribute: 'name', descending: false}]
			});
			grid = dijit.byId("grid1");
			grid.setModel(model);
			grid.setStructure(gridLayout);
			grid2 = dijit.byId("grid2");
		});
		
		var lastSearchValue = "";
		function doSearch(el) {
			if (el.value!=lastSearchValue) {
				grid.model.query = {name:el.value};
				lastSearchValue = el.value;
				grid.model.requestRows();
				
				// Filter the grid2 too.
				grid2.model.query = {name:el.value};
				grid2.model.requestRows();
			}
		}
	</script>


</body>
</html>