我正在尝试构建一个非常简单的Kendo网格,其中的表只有两个列: ID和Name。我已经用服务器端分页和服务器端过滤配置了网格。
所有内容似乎都像预期的那样工作,但是在创建新记录之后,网格显示新记录,但不显示ID字段。在创建时,请求的ID为null,但我在创建后发送id和full对象的值。例如,网格使用新值更新网格。为了确保新创建的记录的ID也显示在Grid中,我需要更改/添加什么?
以下是JSP:
<script>
$(function() {
var dataSource = new kendo.data.DataSource({
transport: {
read: {
url:"http://localhost:8181/baseweb/countrylist",
dataType: "jsonp"
},
update: {
url: "http://localhost:8181/baseweb/countryupdate",
dataType: "jsonp"
},
destroy: {
url: "http://localhost:8181/baseweb/countrydelete",
dataType: "jsonp"
},
create: {
url: "http://localhost:8181/baseweb/countrycreate",
dataType: "jsonp"
},
parameterMap: function(data, operation) {
if (operation !== "read" && data.models) {
return {grid_options: kendo.stringify(data.models)};
}
return {grid_options: kendo.stringify(data)};
}
},
serverPaging: true,
serverFiltering: true,
pageSize: 10,
schema: {
data: "data",
total: "total",
model: {
id: "id",
fields: {
id: { editable: false, nullable: true },
name: { validation: { required: true } }
}
}
}
});
$("#grid").kendoGrid({
dataSource: dataSource,
pageable: true,
filterable: true,
height: 400,
toolbar: ["create"],
columns: [
{ field: "id", title:"Identification"},
{ field: "name", title:"Country Name" },
{ command: ["edit", "destroy"], title: " ", width: "160px" }
],
editable: "popup"
});
});
</script> 参数发送到create:_ 1380846899054回调jQuery19108827040256333442_1380846899052 grid_options {"id":null,“name”:“Sent”}上的服务器。
从服务器作为响应发送回来的参数: jQuery19108827040256333442_1380846899052( {"id":"4028828f4180d64a014180e3bda20002",“name”:“sent”})
我希望服务器发送的ID应该显示在Grid中。我已经搜索了这个论坛,Kendo文档和谷歌的答案,但我无法找到一个解决方案。
我遗漏了什么?
用解决方案更新:
Jack's answer提供了寻找解决方案的线索。我犯了两个错误:
Kendo Grid中的回调似乎期望数据返回到" data :“属性中。在我的响应中,我没有将结果集命名为"data:“。回调还需要数据:属性中的对象的JSONArray。我发送了一个JSONObject,因为我只创建了一个对象。
在我将响应更改为包含data: attribute和JSONArray之后,它完美地工作了。来自客户端的请求参数如下所示:
_ 1386350196768
callback jQuery19101285024500179227_1386350196765
grid_options {"id":null,"name":"Ghana"}编辑后的响应如下:
jQuery19101285024500179227_1386350196765( {"data":[{"id":"2c9323ca42c8df630142c944450b0002","name":"Ghana"}]})希望这对其他人有帮助,因为官方文件中并没有清楚地记录这一点。
发布于 2013-11-12 14:33:07
我也遇到过同样的问题,我认为我可能已经找到了答案。如果在架构中定义了保存结果的对象,则必须返回该对象中创建的链接的结果。示例:
schema: {
data: "data",
total: "total", ....
}示例MVC方法:
public JsonResult CreateNewRow(RowModel rowModel)
{
// rowModel.id will be defaulted to 0
// save row to server and get new id back
var newId = SaveRowToServer(rowModel);
// set new id to model
rowModel.id = newId;
return Json(new {data= new[] {rowModel}});
}发布于 2014-01-16 05:52:03
有个很好的干净的方法.
如果网格是在脚本块中创建的:
dataSource: {
transport: {
read: {
url: "..."
},
create: {
url: "...",
type: "POST",
complete: function(e) {
$("#grid").data("kendoGrid").dataSource.read();
}
},
}...或在HTML中
@(Html.Kendo().Grid<ViewModel>()
.Name("grid")
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(10)
.Model(model =>
{
model.Id(i => i.Cde);
model.Field(i => i.Description).Editable(true);
})
.Read(read => read.Action("EditingInline_Read", "UserGroups"))
.Update(update => update.Action("EditingInline_Update", "UserGroups")).Read("EditingInline_Read", "UserGroups")
.Destroy(delete => delete.Action("EditingInline_Delete", "UserGroups"))
.Create(create => create.Action("EditingInline_Create", "UserGroups")).Read("EditingInline_Read", "UserGroups")
)
.Columns(columns =>
{
columns.Bound(s => s.Decription);
columns.Bound(s => s.enabled);
columns.Command(command => { command.Edit(); command.Destroy(); }).Width(200);
})
.Pageable()
.Sortable()
.Selectable(selectable => selectable
.Mode(GridSelectionMode.Single))
.ToolBar(toolbar => toolbar.Create()))查看CRUD调用,更具体,更新和创建。
https://stackoverflow.com/questions/19171339
复制相似问题