Skip to content

Instantly share code, notes, and snippets.

@moromete
Created March 28, 2013 08:47
Show Gist options
  • Save moromete/5261693 to your computer and use it in GitHub Desktop.
Save moromete/5261693 to your computer and use it in GitHub Desktop.
row disappearing after save
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Test JsonRest store</title>
<meta name="viewport" content="width=570">
<style>
@import "../dojo-1.8.3/dojo/resources/dojo.css";
@import "../dojo-1.8.3/dgrid/css/skins/claro.css";
</style>
<script src="../dojo-1.8.3/dojo/dojo.js"
data-dojo-config="async: true"></script>
<script>
require(["dgrid/OnDemandGrid",
"dgrid/editor",
"dojo/_base/declare", "dojo/store/JsonRest", "dojo/store/Observable",
"dojo/store/Cache", "dojo/store/Memory", "dojo/domReady!"],
function(Grid, editor, declare, JsonRest, Observable, Cache, Memory){
var testStore = Observable(Cache(JsonRest({
target:"rest.php?",
idProperty: "id",
}), Memory()));
var columns = [
editor({label:'Name', field:'name', sortable: false, autoSave:true}, 'text', 'click'),
{label:'Changed', field:'changed', sortable: false}
];
window.grid = new (declare([Grid]))({
store: testStore,
getBeforePut: false,
columns: columns,
query:{test:1} // !!! If this is here after save(PUT request) the row disappear
// even if the query params are not taking part on the PUT request
}, "grid");
});
</script>
</head>
<body class="claro">
<div id="grid"></div>
<button onclick='grid.save();'>Save</div>
</body>
</html>
<?php
date_default_timezone_set('Europe/Berlin');
header("Content-Type: application/json");
if( $_SERVER['REQUEST_METHOD'] == 'GET') {
if (preg_match('/items=(\d*)-(\d*)/', $_SERVER['HTTP_RANGE'], $match)) {
$start = $match[1];
$end = $match[2];
}
$total = 5;
$end = ($end >= $total)?$total-1:$end;
header('Content-Range: items '.$start.'-'.$end.'/'.$total);
$resonse_data=array();
for($i=$start; $i<=$end; $i++ ){
$item = array('id'=>$i,
'name'=>'name '.$i,
'changed'=>date('Y-m-d H:i:s', time()));
array_push($resonse_data, $item);
}
echo json_encode($resonse_data);
}
if( $_SERVER['REQUEST_METHOD'] == 'PUT') {
$input = file_get_contents('php://input');
if(!empty($input)) {
$params = json_decode($input);
}
$item = array('id'=>$params->id,
'name'=>$params->name,
'changed'=>date('Y-m-d H:i:s', time()));
echo json_encode($item);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment