1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
4 <title>Dojox QueryReadStore+grid Demo</title>
5 <style type="text/css">
6 @import "../../../dijit/themes/tundra/tundra.css";
7 @import "../../../dojo/resources/dojo.css";
8 @import "../../../dijit/tests/css/dijitTests.css";
9 /* 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) */
10 @import "../../../dojox/grid/_grid/tundraGrid.css";
13 <script type="text/javascript" src="../../../dojo/dojo.js" djConfig="isDebug:true, parseOnLoad: true"></script>
17 <h1 class="testTitle">Dojox QueryReadStore + Grid demo - paging, sortable and filterable all server-side</h1>
19 <h2>The grid is in HTML, store, model, etc. are JS, sorting is added by extending the model class</h2>
20 <b>Capabilities:</b> load data from server, show data, paging (30 rows at a time), sort, filter<br />
21 You can see that data are loaded upon demand by scrolling down in the grid below line #30,
22 open FireBug and you see a server request being issued, to retreive another 30 rows/items.<br />
24 <input type="text" onkeyup="doSearch(this)" />
25 <div id="grid1" dojoType="dojox.Grid" style="height:300px; width:800px;"></div>
27 <h2>The store and grid are "generated" and connected in HTML, filtering is done via JS</h2>
28 This store is by default sorted descending by name (not as the one above, which is ascending).
29 <div dojoType="dojox.data.QueryReadStore"
31 url="../tests/stores/QueryReadStore.php"
32 requestMethod="post"></div>
33 <div dojoType="dojox.grid.data.DojoData"
36 sortFields="[{attribute: 'capital', descending: true}]"
37 rowsPerPage="30"></div>
38 <div dojoType="dojox.Grid" id="grid2"
40 structure="gridLayout"
41 style="height:300px; width:800px;"></div>
43 <script type="text/javascript">
44 dojo.require("dojo.parser"); // scan page for widgets and instantiate them
45 dojo.require("dojox.grid.Grid");
46 dojo.require("dojox.grid._data.model"); // dojox.grid.data.DojoData is in there
47 dojo.require("dojox.data.QueryReadStore");
54 styles: "text-align:right;",
55 get:function(inRowIndex) { return inRowIndex+1;} // this auto generates a row num
60 styles: "text-align:right;",
67 //formatter: rs.chunk.adminUser.grid.formatUser
73 //formatter: rs.chunk.adminUser.grid.formatUser
78 //styles: "text-align:right;",
80 //formatter: phpr.grid.formatDate
85 //styles: "text-align:right;",
87 //formatter: phpr.grid.formatDate
92 // Connect the model and store AFTER the page is loaded, since we can only access
93 // the widget then, since it will be created just before dojo.addOnLoad() is called.
95 dojo.addOnLoad(function() {
96 // Instanciate the store, pass it to the model, connect them to the grid and add the layout ... just some hand work :-)
97 //var store = new dojox.data.QueryReadStore({url:"../tests/stores/QueryReadStore.php", requestMethod:"post", doClientPaging:false});
98 var store = new dojox.data.QueryReadStore({
99 url:"../tests/stores/QueryReadStore.php",
102 var model = new dojox.grid.data.DojoData(null, null, {
105 sortFields:[{attribute: 'name', descending: false}]
107 grid = dijit.byId("grid1");
108 grid.setModel(model);
109 grid.setStructure(gridLayout);
110 grid2 = dijit.byId("grid2");
113 var lastSearchValue = "";
114 function doSearch(el) {
115 if (el.value!=lastSearchValue) {
116 grid.model.query = {name:el.value};
117 lastSearchValue = el.value;
118 grid.model.requestRows();
120 // Filter the grid2 too.
121 grid2.model.query = {name:el.value};
122 grid2.model.requestRows();