【发布时间】:2014-02-27 12:56:30
【问题描述】:
我正在使用剑道网格 MVC。我想将选定行的 ID 值发送到控制器。阅读剑道文档并搜索一些示例。问题是网格数据源的 select() 函数出错。
function editRow() {
var grid = $("#grid").data("kendoGrid");
var selectedRow = grid.select(); // Getting error on this line(Cannot call method 'value' of undefined )
var index = selectedRow.index();
alert(index);
};
查看:
@(Html.Kendo().Grid<AIS.UI.WebService.Proxy.DSrvAllService.AMBULANCEDEFINITIONS>() //Bind the grid to ViewBag.Products
.Name("grid")
.Columns(columns =>
{
columns.Bound(product => product.DESCRIPTION).Title("<strong>Ambulance Description</strong>").Width("20%");
columns.Bound(product => product.CODE).Title("<strong>Ambulance CODE</strong>").Width("20%");
columns.Command(commands =>
{
commands.Custom("").Text("editteam").HtmlAttributes(new { id = "editteam", onClick = "editRow()" });
commands.Destroy();
}).Title("Operations").Width("10%");
})
.ToolBar(toolbar =>
{
toolbar.Create().HtmlAttributes(new { id = "addbutton", style = "font-weight:bold;color:blue" }).Text("Add Records"); // The "create" command adds new data items
toolbar.Save();
})
.Editable(editable => editable.Mode(GridEditMode.InCell))
.Pageable(pager => pager
.PageSizes(true)
.Input(true)
.Refresh(true)
)
.Sortable() // Enable sorting
.DataSource(dataSource => dataSource
.Ajax()
.ServerOperation(true)
.Events(events => events.Error("onError"))
.Model(model =>
{
model.Id(product => product.ID); // Specify the property which is the unique identifier of the model
model.Field(product => product.ID).Editable(false).DefaultValue(Guid.Empty);
model.Field(p => p.DESCRIPTION).Editable(true);
model.Field(product => product.CODE).Editable(true);
})
.Events(events => events.Error("onError"))
.Create(create => create.Action("AmbulanceCreate", "Administrator")) // Action invoked when the user saves a new data item
.Read(read => read.Action("AmbulanceRead", "Administrator")) // Action invoked when the grid needs data
.Update(update => update.Action("AmbulanceUpdate", "Administrator")) // Action invoked when the user saves an updated data item
.Destroy(destroy => destroy.Action("AmbulanceDelete", "Administrator")) // Action invoked when the user removes a data item
))
更新(已解决)
获取按下自定义按钮的行的 ID 值:
function EditName(e) {
var dataItem = this.dataItem($(e.currentTarget).closest("tr"));
var id = dataItem.ID;
alert(id);
还需要像这样将数据传递给函数:
commands.Custom("Edit Team").Click("EditName")
【问题讨论】:
-
editRow函数何时调用?格子是当时生成的吗?是否只选择带有 jQuery 的“网格”返回生成的元素?
标签: jquery asp.net-mvc model-view-controller kendo-ui