我是Kendo Grid的新手。任何人都可以帮助我。在网格中如果没有给出数据点击更新按钮验证会被提出。但是行会更新。更新应该不会发生
@(Html.Kendo().Grid<Project.Models.EmployeeDetail>()
.Name("EmployeeGrid")
.Columns(col =>
{
col.Bound(p => p.EName).Width("15%").Title("Name")
col.Bound(a => a.Address).Title("Address").Width("15%");
col.Command(a => { a.Edit(); }).Width("10%").Title("Edit");
col.Command(a => {a.Destroy();}).Title("Delete").Width("10%");
}
)
.Pageable()
.ToolBar(toolbar => toolbar.Create().Text("Add"))
.Editable(editable => editable.Mode(GridEditMode.InLine))
.DataSource(source => source
.Ajax()
.PageSize(4)
.Model(a => a.Id(b => b.Name))
.Read(read => read.Action("EmpGrid", "Employee"))
.Create(create => create.Action("EmpGridCreate", "Employee"))
.Update(update => update.Action("EmpGridUpdate", "Employee"))
.Destroy(del => del.Action("EmpGridDelete", "Employee"))
)
.Events(e =>
{
e.Save("SaveDetails");
e.Edit("EditDetails");
}))
保存事件代码:
function SaveDetails(e)
{
var result=true;
writeMultipleMessage("error", "", "EName");
var EmpName = $("#EName").val();
if(EmpName ==""|| EmpName == null || EmpName ==undefined)
{
writeMultipleMessage("error", "Please Provide Employee Name", "EName");
e.preventDefault();
result = false;
}
else
{
e.model.EName=EName;
}
writeMultipleMessage("error", "", "Address");
var AddressDet=$("#Address").val();
if (AddressDet == "" || AddressDet == null || AddressDet == undefined) {
writeMultipleMessage("error", "Please provide Address", "Address");
e.preventDefault();
result = false;
}
else {
e.model.Address = Address;
}
var Grid = $("#EmployeeGrid").data("kendoGrid");
Grid.refresh();
}
我在上面显示了我的代码 更新是命中保存Event.Row更新虽然抛出了验证。不应该更新 任何人都可以提出一些想法。谢谢。如果这是一个重复的问题,请等待。
答案 0 :(得分:0)
问题是$(&#34; #EmpName&#34;。)。val()对您尝试更新的行无效。您必须在DOM对象中查找Column值的Kendo Grid行。我们可以使用$(e.cell).find()来找到你需要为该行获取的列。
尝试使用这样的JavaScript:
function SaveDetails(e)
{
var result=true;
writeMultipleMessage("error", "", "EName");
var EmpName = $(e.cell).find("#EName").val();
if(EmpName ==""|| EmpName == null || EmpName ==undefined)
{
writeMultipleMessage("error", "Please Provide Employee Name", "EName");
e.preventDefault();
result = false;
}
else
{
e.model.EName=EName;
}
writeMultipleMessage("error", "", "Address");
var AddressDet = $(e.cell).find("#Address").val();
if (AddressDet == "" || AddressDet == null || AddressDet == undefined) {
writeMultipleMessage("error", "Please provide Address", "Address");
e.preventDefault();
result = false;
}
else {
e.model.Address = Address;
}
var Grid = $("#EmployeeGrid").data("kendoGrid");
Grid.refresh();
}
以下是Kendo UI的Kendo UI Grid示例宝库,以获得进一步的帮助: