[英]PK of Kendo Grid Row
<%: Html.Kendo().Grid<Model>()
.Name("Grid")
.BindTo((IEnumerable<Model>)ViewBag.List)
.Columns(columns =>
{
columns.Bound(p => p.PK).Title("pk");
columns.Bound(p => p.NAME).Title("Name");
columns.Command(command => command.Custom("Delete").Click("Delete")).Width(100);
})
%>
<div id="modalWindow">
<h2>Delete?</h2>
<button id="yes" class="k-button">Yes</button>
<button id="no" class="k-button">No</button>
</div>
<script>
var wnd;
$(document).ready(function () {
wnd = $("#modalWindow").kendoWindow({
title: "Delete confirmation",
modal: true,
visible: false,
resizable: false,
width: 300
}).data("kendoWindow");
});
function Delete(e) {
e.preventDefault();
var grid = this;
var row = $(e.currentTarget).closest("tr");
wnd.center().open();
$("#yes").unbind('click').click(function () {
$.ajax({
type: 'POST',
url: '/Home/Delete',
data: ???
contentType: 'application/json; charset=utf-8',
success: function (result) {
},
error: function (err, result) {
alert("Error in delete" + err.responseText);
}
});
grid.removeRow(row);
wnd.close();
});
$("#no").unbind('click').click(function () {
wnd.close();
});
}
</script>
Hello, 你好,
I want to delete the row of the related custom delete button of a Kendo Grid. 我想删除Kendo网格的相关自定义删除按钮的行。 The script works great but I have a problem with data.
该脚本很好用,但我对数据有疑问。 I don't know how to get the PK of the row and I need it to delete the record.
我不知道如何获取该行的PK,我需要它来删除记录。
How could I get it on click of my custom button? 单击自定义按钮如何获得它?
Regards 问候
Do you know the underlying dataItem's ID property ? 您知道基础dataItem的ID属性吗? You can grab the dataItem from the grid's datasource once you have the row.
一旦有了该行,就可以从网格的数据源中获取dataItem。 So after the
var row = $(e.currentTarget).closest('tr');
所以在
var row = $(e.currentTarget).closest('tr');
you can add a var dataItem = grid.dataItem(row);
您可以添加
var dataItem = grid.dataItem(row);
And then you should be able to get the id property of the dataItem dataItem.id
(or some such); 然后,您应该能够获得dataItem
dataItem.id
的id属性(或类似的东西);
You need to use the dataItem
function in order to convert the tr
element into a data object: 您需要使用
dataItem
函数才能将tr
元素转换为数据对象:
function Delete(e) {
e.preventDefault();
var grid = this;
var row = $(e.currentTarget).closest("tr");
var obj = grid.dataItem(row); //<---
wnd.center().open();
$("#yes").unbind('click').click(function () {
$.ajax({
type: 'POST',
url: '/Home/Delete',
data: obj.PK, //<---
contentType: 'application/json; charset=utf-8',
success: function (result) {
},
error: function (err, result) {
alert("Error in delete" + err.responseText);
}
});
grid.removeRow(row);
wnd.close();
});
$("#no").unbind('click').click(function () {
wnd.close();
});
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.