Files
openlayers/master/examples/test_data_grid_setStore.html
Éric Lemoine 5d14b9e2d4 Updated
2013-02-20 10:38:25 +01:00

105 lines
3.8 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Test DataGrid - setStore</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 "../resources/Grid.css";
@import "../resources/tundraGrid.css";
body {
font-size: 0.9em;
font-family: Geneva, Arial, Helvetica, sans-serif;
}
button {
margin: 20px;
}
.heading {
font-weight: bold;
padding-bottom: 0.25em;
}
.grid {
width: 65em;
padding: 1px;
}
</style>
<script type="text/javascript" src="../../../dojo/dojo.js"
djConfig="isDebug:false, parseOnLoad: true"></script>
<script type="text/javascript">
dojo.require("dijit.dijit"); // optimize: load dijit layer
dojo.require("dojox.grid.DataGrid");
dojo.require("dojo.data.ItemFileWriteStore");
dojo.require("dojo.parser");
dojo.declare("dojox.grid.SlowFileWriteStore", dojo.data.ItemFileWriteStore, {
_fetchItems: function( /*Object*/ keywordArgs,
/*Function*/ findCallback,
/*Function*/ errorCallback){
setTimeout(dojo.hitch(this, function(){
dojo.data.ItemFileWriteStore.prototype._fetchItems.call(this, keywordArgs, findCallback, errorCallback);
}), 10000);
}
});
function createStore(type)
{
// Create a new datastore and use the Grid's setStore() function to change it.
var newStore, args = {}, grid = dijit.byId("grid");
if(type=="slow"){
// Slow Loading store
args.url = "../../../dijit/tests/_data/countries.json";
newStore = new dojox.grid.SlowFileWriteStore(args);
grid.setStore(newStore, { name: '*' });
}else if(type=="empty"){
// Empty result set -- set the Grid's query to something with no results
args.url = "../../../dijit/tests/_data/countries.json";
newStore = new dojo.data.ItemFileWriteStore(args);
grid.setStore(newStore, { name: 'nonexist' });
}else if(type=="error"){
// Error result -- set the url to a file that doesn't exist
args.url = "../../../dijit/tests/_data/countries-no.json";
newStore = new dojo.data.ItemFileWriteStore(args);
grid.setStore(newStore);
}else{//type=="standard"
args.url = "../../../dijit/tests/_data/countries.json";
newStore = new dojo.data.ItemFileWriteStore(args);
grid.setStore(newStore);
}
}
</script>
<script type="text/javascript" src="support/test_data.js"></script>
</head>
<body class="tundra">
<h1>dojox.grid.DataGrid using setStore() to change datastores.</h1>
<p>
This page demonstrates the ability to change datastores using the
DataGrid's setStore() function. Click on any of the buttons above
the Grid to set a new store and refresh the Grid display.
</p>
<p>
<button onclick="createStore('standard');">Standard Store</button>
<button onclick="createStore('slow');">Slow Loading Store</button>
<button onclick="createStore('empty');">Empty Store</button>
<button onclick="createStore('error');">Error Store</button>
</p>
<span dojoType="dojo.data.ItemFileWriteStore"
jsId="jsonStore" url="../../../dijit/tests/_data/countries.json">
</span>
<div class="heading">Grid Test</div>
<table dojoType="dojox.grid.DataGrid"
jsid="grid" id="grid" class="grid" autoHeight="15" noDataMessage="Sorry, there is no data available."
store="jsonStore" query="{ name: '*' }" rowsPerPage="20" rowSelector="20px">
<thead>
<tr>
<th field="name" width="300px">Country/Continent Name</th>
<th field="type" width="auto">Type</th>
</tr>
</thead>
</table>
</body>
</html>