Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'rest' into pagination

  • Loading branch information...
commit 6816c04918674d8639388964cec99fe00b2d641f 2 parents a1999bb + 7191c97
@kriszyp authored
Showing with 44 additions and 6 deletions.
  1. +16 −6 test/JsonRest.html
  2. +28 −0 test/data/rest.php
View
22 test/JsonRest.html
@@ -22,19 +22,27 @@
<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/Keyboard", "dojo/_base/declare", "dojo/store/JsonRest", "dojo/domReady!"],
- function(List, Grid, Selection, Keyboard, declare, JsonRest){
- var testStore = new JsonRest({target:"./", idProperty: "order"});
+ 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"}), Memory()));
+ testStore.getChildren = function(parent, options){
+ return testStore.query({parent: parent.id}, options);
+ };
var columns = [
- {label:'Name', field:'name', sortable: false},
- {label:'Description', field:'description', sortable: false}
+ Tree({label:'Name', field:'name', sortable: false}),
+ {label:'Id', field:'id', sortable: false},
+ Editor({label:'Comment', field:'comment', sortable: false}, "text")
];
window.grid = new (declare([Grid, Selection, Keyboard]))({
- query: "data/rest.js",
store: testStore,
columns: columns
}, "grid");
+ deleteSelected = function(){
+ for(var i in grid.selection){
+ testStore.remove(i);
+ }
+ }
});
</script>
@@ -42,5 +50,7 @@
<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>
View
28 test/data/rest.php
@@ -0,0 +1,28 @@
+<?php
+header("Content-Type: application/json");
+$id_prefix = "";
+if(isset($_GET["parent"])){
+ $id_prefix = $_GET["parent"]."-";
+}
+if(isset($_SERVER["HTTP_RANGE"])){
+ preg_match('/(\d+)-(\d+)/',$_SERVER["HTTP_RANGE"], $matches);
+
+ $start = $matches[1];
+ $end = $matches[2];
+ if($end > 120){
+ $end = 120;
+ }
+}else{
+ $start = 0;
+ $end = 40;
+}
+header("Content-Range: " . "items ".$start."-".$end."/120");
+echo '[';
+for ($i = $start; $i <= $end; $i++) {
+ if($i != $start){
+ echo ',';
+ }
+ echo '{"id":"'.$id_prefix.$i.'","name":"Item '.$i.'","comment":"hello"}';
+}
+echo ']';
+?>
Please sign in to comment.
Something went wrong with that request. Please try again.