| 1 |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" |
| 2 |
"http://www.w3.org/TR/html4/loose.dtd"> |
| 3 |
<html> |
| 4 |
<head> |
| 5 |
<title>dojox.grid.DataGrid using multiple store implementations.</title> |
| 6 |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"></meta> |
| 7 |
<style type="text/css"> |
| 8 |
@import "../../../dijit/themes/tundra/tundra.css"; |
| 9 |
@import "../../../dojo/resources/dojo.css"; |
| 10 |
@import "../../../dijit/tests/css/dijitTests.css"; |
| 11 |
@import "../resources/Grid.css"; |
| 12 |
@import "../resources/tundraGrid.css"; |
| 13 |
|
| 14 |
#grid, #grid2, #grid3, #grid4, #grid5, #grid6{ |
| 15 |
width: 65em; |
| 16 |
height: 25em; |
| 17 |
padding: 1px; |
| 18 |
} |
| 19 |
</style> |
| 20 |
<script type="text/javascript" src="../../../dojo/dojo.js" |
| 21 |
data-dojo-config="isDebug: true, debugAtAllCosts: false, parseOnLoad: true"></script> |
| 22 |
<script type="text/javascript"> |
| 23 |
dojo.require("dijit.dijit"); |
| 24 |
dojo.require("dojox.grid.DataGrid"); |
| 25 |
dojo.require("dojo.data.ItemFileReadStore"); |
| 26 |
dojo.require("dojox.data.CsvStore"); |
| 27 |
dojo.require("dojox.data.XmlStore"); |
| 28 |
dojo.require("dojox.data.FlickrStore"); |
| 29 |
dojo.require("dojox.data.OpmlStore"); |
| 30 |
dojo.require("dojox.data.HtmlStore"); |
| 31 |
dojo.require("dojo.parser"); |
| 32 |
</script> |
| 33 |
|
| 34 |
<script type="text/javascript"> |
| 35 |
var formatHref = function(value, rowIndex) { |
| 36 |
return "<a href=\"" + value + "\" target=\"_blank\">Image Link</a>"; |
| 37 |
} |
| 38 |
|
| 39 |
var rowView = { cells: [ new dojox.grid.cells.RowIndex({ width: 5 }) ], noscroll: true }; |
| 40 |
|
| 41 |
var layoutMovies = [ |
| 42 |
// view 1 |
| 43 |
rowView, |
| 44 |
// view 2 |
| 45 |
[ |
| 46 |
{ field: "Title", width: 'auto' }, |
| 47 |
{ field: "Year", width: 5 }, |
| 48 |
{ field: "Producer", width: 20 } |
| 49 |
] |
| 50 |
]; |
| 51 |
|
| 52 |
var layoutCountries = [ |
| 53 |
// view 1 |
| 54 |
rowView, |
| 55 |
// view 2 |
| 56 |
[ |
| 57 |
{ field: 'name', width: 'auto' }, |
| 58 |
{ field: 'type', width: 8 } |
| 59 |
] |
| 60 |
]; |
| 61 |
|
| 62 |
var layoutBooks = [ |
| 63 |
// view 1 |
| 64 |
rowView, |
| 65 |
// view 2 |
| 66 |
[ |
| 67 |
{ field: "title", width: 'auto' }, |
| 68 |
{ field: "isbn", width: '8' } |
| 69 |
] |
| 70 |
]; |
| 71 |
|
| 72 |
//Lay out the Flickr data so one column is a URL. This makes use of the |
| 73 |
//get function of a cell. |
| 74 |
var layoutFlickrData = [ |
| 75 |
// view 1 |
| 76 |
rowView, |
| 77 |
// view 2 |
| 78 |
[ |
| 79 |
{ name: "Title", field: "title", width: 'auto' }, |
| 80 |
{ name: "Image URL", field: "imageUrl", width: '15', formatter: formatHref} |
| 81 |
] |
| 82 |
]; |
| 83 |
|
| 84 |
var layoutOpmlData = [ |
| 85 |
// view 1 |
| 86 |
rowView, |
| 87 |
// view 2 |
| 88 |
[ |
| 89 |
{ name: 'Name', field: 'text', width: 'auto'}, |
| 90 |
{ name: 'Type', field: 'type', width: '8' } |
| 91 |
] |
| 92 |
]; |
| 93 |
|
| 94 |
var layoutHtmlTable = [ |
| 95 |
// view 1 |
| 96 |
rowView, |
| 97 |
// view 2 |
| 98 |
[ |
| 99 |
{ name: 'Column 1', field: 'Column 1', width: 'auto'}, |
| 100 |
{ name: 'Column 2', field: 'Column 2', width: 'auto'}, |
| 101 |
{ name: 'Column 3', field: 'Column 3', width: 'auto'}, |
| 102 |
{ name: 'Column 4', field: 'Column 4', width: 'auto'} |
| 103 |
] |
| 104 |
]; |
| 105 |
</script> |
| 106 |
</head> |
| 107 |
<body class="tundra"> |
| 108 |
<h1>dojox.grid.DataGrid using multiple store implementations.</h1> |
| 109 |
<p> |
| 110 |
This page demonstrates the Grid can display data accessed by dojo.data |
| 111 |
implementing Datastores. Each of the datastores used stores data in a |
| 112 |
different format, and as this test and demonstration page shows, the |
| 113 |
logic for rendering the data is virtually identical. You define your |
| 114 |
source store and then you define the layout, which maps the data |
| 115 |
attribute names to columns in the grid. You can even perform |
| 116 |
cusomization of what is displayed, as demonstrated in the |
| 117 |
dojox.data.FlickrStore layout. The image url is displayed as a |
| 118 |
clickable link that opens a new page. |
| 119 |
</p> |
| 120 |
<p> |
| 121 |
The choice of stores used were ones that did not require back end |
| 122 |
services to function for sake of simplicity. There is no reason that |
| 123 |
dojox.data.QueryReadStore could not be used with grid as well, it just |
| 124 |
requires a back end service to send it the query results. |
| 125 |
</p> |
| 126 |
<p><b>Stores used:</b></p> |
| 127 |
<ul> |
| 128 |
<li>dojo.data.ItemFileReadStore</li> |
| 129 |
<li>dojox.data.CsvStore</li> |
| 130 |
<li>dojox.data.XmlStore</li> |
| 131 |
<li>dojox.data.FlickrStore</li> |
| 132 |
<li>dojox.data.OpmlStore</li> |
| 133 |
<li>dojox.data.HtmlTableStore</li> |
| 134 |
</ul> |
| 135 |
|
| 136 |
<h2>dojo.data.ItemFileReadStore:</h2> |
| 137 |
<i>Displays a list of countries through ItemFileReadStore format.</i> |
| 138 |
<span dojoType="dojo.data.ItemFileReadStore" |
| 139 |
data-dojo-id="jsonStore" url="../../../dijit/tests/_data/countries.json"> |
| 140 |
</span> |
| 141 |
<div id="grid" dojoType="dojox.grid.DataGrid" elasticView="2" query="{ name: '*' }" rowsPerPage="20" |
| 142 |
store="jsonStore" structure="layoutCountries" rowSelector="20px"> |
| 143 |
</div> |
| 144 |
|
| 145 |
|
| 146 |
<h2>dojox.data.CsvStore:</h2> |
| 147 |
<i>Displays a list of movies that were stored in CSV format.</i> |
| 148 |
<span dojoType="dojox.data.CsvStore" |
| 149 |
data-dojo-id="csvStore" url="support/movies.csv"> |
| 150 |
</span> |
| 151 |
<div id="grid2" dojoType="dojox.grid.DataGrid" elasticView="2" query="{ Title: '*' }" rowsPerPage="5" |
| 152 |
store="csvStore" structure="layoutMovies" rowSelector="20px"> |
| 153 |
</div> |
| 154 |
|
| 155 |
<h2>dojox.data.XmlStore:</h2> |
| 156 |
<i>Displays a list of books that were stored in XML format.</i> |
| 157 |
<span dojoType="dojox.data.XmlStore" |
| 158 |
data-dojo-id="xmlStore" url="support/books.xml"> |
| 159 |
</span> |
| 160 |
<div id="grid3" dojoType="dojox.grid.DataGrid" elasticView="2" query="{ title: '*' }" rowsPerPage="5" |
| 161 |
store="xmlStore" structure="layoutBooks" rowSelector="20px"> |
| 162 |
</div> |
| 163 |
|
| 164 |
|
| 165 |
<h2>dojox.data.FlickrStore:</h2> |
| 166 |
<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> |
| 167 |
<span dojoType="dojox.data.FlickrStore" |
| 168 |
data-dojo-id="flickrStore"> |
| 169 |
</span> |
| 170 |
<div id="grid4" dojoType="dojox.grid.DataGrid" elasticView="2" query="{ tags: '3dny' }" |
| 171 |
rowsPerPage="5" |
| 172 |
store="flickrStore" structure="layoutFlickrData" rowSelector="20px"> |
| 173 |
</div> |
| 174 |
|
| 175 |
<h2>dojox.data.OpmlStore:</h2> |
| 176 |
<i>Scans an Opml based document for all items of type 'country'</i> |
| 177 |
<span dojoType="dojox.data.OpmlStore" |
| 178 |
data-dojo-id="opmlStore" url="support/geography.xml"> |
| 179 |
</span> |
| 180 |
<div id="grid5" dojoType="dojox.grid.DataGrid" elasticView="2" query="{ type: 'country' }" |
| 181 |
queryOptions="{ deep: true }" rowsPerPage="5" |
| 182 |
store="opmlStore" structure="layoutOpmlData" rowSelector="20px"> |
| 183 |
</div> |
| 184 |
|
| 185 |
|
| 186 |
<h2>dojox.data.HtmlStore:</h2> |
| 187 |
<i>Loads the grid from an HTML Table.</i> |
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
<table id="tableExample" style="display: none;"> |
| 193 |
<thead> |
| 194 |
<tr> |
| 195 |
<th>Column 1</th> |
| 196 |
<th>Column 2</th> |
| 197 |
<th>Column 3</th> |
| 198 |
<th>Column 4</th> |
| 199 |
</tr> |
| 200 |
</thead> |
| 201 |
<tbody> |
| 202 |
<tr> |
| 203 |
<td>This</td> |
| 204 |
<td>is</td> |
| 205 |
<td></td> |
| 206 |
<td>empty in column 3</td> |
| 207 |
</tr> |
| 208 |
<tr> |
| 209 |
<td>This</td> |
| 210 |
<td>is</td> |
| 211 |
<td>a</td> |
| 212 |
<td>value</td> |
| 213 |
</tr> |
| 214 |
<tr> |
| 215 |
<td>Who?</td> |
| 216 |
<td>What?</td> |
| 217 |
<td>When?</td> |
| 218 |
<td>Where?</td> |
| 219 |
</tr> |
| 220 |
<tr> |
| 221 |
<td>She</td> |
| 222 |
<td>sells</td> |
| 223 |
<td>sea</td> |
| 224 |
<td>shells</td> |
| 225 |
</tr> |
| 226 |
</tbody> |
| 227 |
</table> |
| 228 |
<span dojoType="dojox.data.HtmlStore" |
| 229 |
data-dojo-id="htmlStore" dataId="tableExample"> |
| 230 |
</span> |
| 231 |
<div id="grid6" dojoType="dojox.grid.DataGrid" elasticView="2" query="{}" |
| 232 |
store="htmlStore" rowsPerPage="5" structure="layoutHtmlTable" rowSelector="20px"> |
| 233 |
</div> |
| 234 |
|
| 235 |
</body> |
| 236 |
</html> |
| 237 |
|
| 238 |
|