【发布时间】:2017-12-13 21:34:02
【问题描述】:
在我的剑道网格中,当我通过弹出编辑器进行编辑后,更新按钮不起作用。“结果”是 Ajax 调用响应,因为我不使用服务我不需要“读取”部分,这就是我评论的原因它,
数据源初始化:
dataSource = new kendo.data.DataSource({
transport: {
//read: {
// url: result,
// dataType: "json"
//},
update: {
url: "/AdminTool/update_grid",
dataType: "json"
},
parameterMap: function (options, operation) {
if (operation !== "read" && options.models) {
return { models: kendo.stringify(options.models) };
}
}
},
batch: true,
pageSize: 20,
schema: {
model: {
id: "DeviceIP",
fields: {
DeviceIP: { editable: false, nullable: true },
Producer: { type: "string" },
Model: { type: "string" },
DeviceType: { type: "string" },
Description: { type: "string" },
Username: { type: "string" },
Password: { type: "string" },
PublicIP: { type: "string" },
}
}
}
});
剑道网格初始化:
$("#turbingrid").kendoGrid({
dataSource: result,
scrollable: false,
columns: [
{ field: 'DeviceIP', title: 'DeviceIP', width: '100px', id: 'DeviceIP' },
{ field: 'Producer', title: 'Producer', width: '80px', editor: ProductNameDropDownEditor, },
{ field: 'Model', title: 'Model', width: '120px' },
{ field: 'DeviceType', title: 'DeviceType', width: '100px', editor:deviceTypesList },
{ field: 'Description', title: 'Description', width: '100px' },
{ field: 'Username', title: 'Username',width:'120px' },
{ field: 'Password', title: 'Password', width: '100px' },
{ field: 'PublicIP', title: 'PublicIP', width: '120px' },
{ command: ["edit"], title: " ", width: "100px" }],
editable: "popup",
edit: function() {
document.getElementsByName("DeviceIP")[0].disabled = true;
},
editable: "popup"
});
栏目编辑:
function ProductNameDropDownEditor(container, options) {
$('<input name="Producer" data-type="string"\">')
.appendTo(container)
.kendoDropDownList({
valuePrimitive: true,
dataSource: mydata,
dataTextField: "Text",
dataValueField: "Text",
});
}
function deviceTypesList(container, options) {
$('<input name="DeviceType" data-type="string" \">')
.appendTo(container)
.kendoDropDownList({
dataSource: mydata_deviceType,
dataTextField: "Text",
dataValueField: "Text",
//dataValueField: "ProductName",
});
}
我的控制者:
[HttpPost]
public ActionResult update_grid(TurbineDvce frm)
{
try
{
// TODO: Add update logic here
return RedirectToAction("Index");
}
catch
{
return View();
}
}
我想通过的模型
public class TurbineDvce
{
public string TurbineId { get; set; }
public string DeviceIP { get; set; }
public string Producer { get; set; }
public string Model { get; set; }
public string DeviceType { get; set; }
public string Comments { get; set; }
public string Description { get; set; }
public string Username { get; set; }
public string Password { get; set; }
public string PublicIP { get; set; }
}
【问题讨论】:
-
一些注意事项,如果您想在应用更改时自动调用服务器,您可能需要查看
autoSync。或者,您可以手动拨打sync。您可以选择使用提供的transport.update方法或使用AJAX in theupdatefunction。 -
您可以指定
data与请求一起发送。或者可以选择使用parameter.map -
@Sandman 谢谢,但老实说我不知道我应该如何实现第二个,我不知道我应该单独编写还是放在我的剑道网格代码之间,
-
您选择的解决方案可能取决于所需的更新功能行为。逐行更新,即在每次编辑行后调用
update_grid,还是在保存所有更新的行时调用单个更新?根据您的偏好更新您的问题,以及您的控制器方法 (update_grid) 以及您认为需要提供更多上下文的任何其他代码。 -
@Sandman 我的每一行都是单个更新,但我应该如何让更新按钮工作?我应该为“编辑:”编写代码?
标签: javascript model-view-controller kendo-ui kendo-grid