我正在使用Kendo UI Grid。基本上,我想要做的是将网格绑定在以json格式发送的远程数据上并能够编辑它。 网格接收数据并按我的意愿显示它。但是,当我想编辑一个单元格时,php文件中收到的请求为null,发送的类型为“create”,而我希望它是“更新”。
以下是使用的代码: -javascript包含网格声明
$(document).ready(function() {
var dataSource = new kendo.data.DataSource({
batch: true,
transport: {
read: {
dataType: "json",
type: "POST",
url: "testgrid.php?type=read"
},
update: {
dataType: "json",
type: "POST",
url: "testgrid.php?type=update"
},
create: {
dataType: "json",
type: "POST",
url: "testgrid.php?type=create"
},
destroy: {
dataType: "json",
type: "POST",
url: "testgrid.php?type=destroy"
}
},
schema: {
data: function(result) {
return result.Result || result.data;
},
model: {
id: "bbmindex",
fields: {
totalvente: {type: "number"}
}
},
total: function(result) {
return result.totalData || result.PageSize || result.length || 0;
}
}
});
var param = {
columns: [
{
field: "naturetravaux", title: "nature travaux"
},
{
field: "totalvente", title: "total vente"
}
],
selectable: 'multiplerows',
editable: true,
toolbar: ["create", "save", "cancel", "destroy"],
dataSource: dataSource
};
$("#grid").kendoGrid(param);
});
- php脚本将数据发送到dataSource
<?php
header('Content-Type: application/json');
$request = json_decode(file_get_contents('php://input'));
$type = $_GET['type'];
$result = null;
if ($type == 'create') {
some code
} else if ($type == 'read') {
some code which send the data
} else if ($type == 'update') {
some code
}
echo json_encode($result);
?>
关于这里有什么问题的任何想法? 任何帮助将非常感激, 谢谢你提前
马丁
答案 0 :(得分:0)
如果您的服务器收到create
,则因为已修改记录的id
为0
,null
或undefined
。请检查您是否从服务器获取了一个名为bbmindex
且不是0
答案 1 :(得分:0)
您希望将请求发布为JSON,但Kendo DataSource默认情况下不会这样做。您需要使用parameterMap选项并使其返回JSON:
parameterMap: function(data, type) {
return kendo.stringify(data);
}