forked from SitePen/dgrid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
JsonRest.html
68 lines (66 loc) · 2.3 KB
/
JsonRest.html
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
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Test JsonRest store</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<meta name="viewport" content="width=570" />
<style type="text/css">
@import "../../dojo/resources/dojo.css";
@import "../css/skins/claro.css";
h2 {
margin: 12px;
}
.heading {
font-weight: bold;
padding-bottom: 0.25em;
}
.ui-widget{
margin: 10px;
}
</style>
<script type="text/javascript" src="../../dojo/dojo.js"
data-dojo-config="async: true"></script>
<script type="text/javascript">
require(["dgrid/List", "dgrid/OnDemandGrid","dgrid/Selection", "dgrid/Editor", "dgrid/Keyboard", "dgrid/Tree", "dojo/_base/declare", "dojo/store/JsonRest", "dojo/store/Observable", "dojo/store/Cache", "dojo/store/Memory", "dojo/domReady!"],
function(List, Grid, Selection, Editor, Keyboard, Tree, declare, JsonRest, Observable, Cache, Memory){
var testStore = Observable(Cache(JsonRest({
target:"./data/rest.php?",
idProperty: "id",
query: function(query, options){
// have to manually adjust the query to get rid of the double ?? that trips php up
if(query.parent){
query = "parent=" + parent;
}
return JsonRest.prototype.query.call(this, query, options);
}
}), Memory()));
testStore.getChildren = function(parent, options){
return testStore.query({parent: parent.id}, options);
};
var columns = [
Tree({label:'Name', field:'name', sortable: false}),
{label:'Id', field:'id', sortable: false},
Editor({label:'Comment', field:'comment', sortable: false}, "text"),
Editor({label:'Boolean', field:'boo', sortable: false, autoSave: true}, "checkbox")
];
window.grid = new (declare([Grid, Selection, Keyboard]))({
store: testStore,
getBeforePut: false,
columns: columns
}, "grid");
deleteSelected = function(){
for(var i in grid.selection){
testStore.remove(i);
}
}
});
</script>
</head>
<body class="claro">
<h2>A basic grid with JsonRest store</h2>
<div id="grid"></div>
<button onclick='deleteSelected()'>Delete Page</div>
<button onclick='grid.save();'>Save</div>
</body>
</html>