Kendo ui 如何防止取消事件更改网格行的颜色?
我搜索数据,然后绑定到我的网格。在网格的Kendo ui 如何防止取消事件更改网格行的颜色?,kendo-ui,kendo-grid,kendo-asp.net-mvc,Kendo Ui,Kendo Grid,Kendo Asp.net Mvc,我搜索数据,然后绑定到我的网格。在网格的databound事件中,我根据单元格的值更改行背景颜色。这样行。但是,当我单击网格中的“编辑”按钮,然后单击“取消”按钮时,网格不再设置背景色。我试图在Cancel事件中调用databound事件,但它不起作用。如何防止取消事件更改网格颜色 网格 @(Html.Kendo().Grid(Model) .Name("mygrid") .Events(e=>e.DataBound("dataBo
databound
事件中,我根据单元格的值更改行背景颜色。这样行。但是,当我单击网格中的“编辑”按钮,然后单击“取消”按钮时,网格不再设置背景色。我试图在Cancel
事件中调用databound
事件,但它不起作用。如何防止取消事件更改网格颜色
网格
@(Html.Kendo().Grid(Model)
.Name("mygrid")
.Events(e=>e.DataBound("dataBound"))
.Columns(columns =>
{
columns.Bound(p =>p.StudentName).Title("StudentName");
columns.Command(command =>
{
command.Edit().UpdateText("Edit");
command.Destroy().Text("Delete");
}).Width(160);
})
.Editable(editable => editable.Mode(GridEditMode.PopUp)
.TemplateName("SudentEditor")
.Window(configurator=>configurator.Width(500)
.Title("EditStudent")))
.Scrollable()
.Events(events=>events.Cancel("onCancel"))
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(20)
.Model(model =>
{
model.Id(p => p.Id);
})
.Read(read => read.Action("GetStudentForGrid", "Student"))
.Create(create=>create.Action("CreateSudent","Equipment"))
.Update(update => update.Action("UpdateStudent", "Student"))
.Destroy(destory=>destory.Action("DestroyStudent","Student"))
.Events(events => events.Error("error_handler"))
))
数据绑定事件
//change grid color
function dataBound(e) {
$("#mygrid tbody tr").each(function(i) {
$(this).find("td:lt(9)").css("backgroundColor", '#000000');
});
}
//I try to call preventDefault event and close the PopUp window
//,but the background is still grey
function onCancel(e) {
//e.preventDefault();
//e.container.parent().css("display", "none");
// e.sender.clearSelection();
dataBound();
}
取消事件
//change grid color
function dataBound(e) {
$("#mygrid tbody tr").each(function(i) {
$(this).find("td:lt(9)").css("backgroundColor", '#000000');
});
}
//I try to call preventDefault event and close the PopUp window
//,but the background is still grey
function onCancel(e) {
//e.preventDefault();
//e.container.parent().css("display", "none");
// e.sender.clearSelection();
dataBound();
}
您可以在
cancel-ent
中使用grid.cancelRow()
,然后刷新网格。只需在取消事件中刷新网格即可。它将再次触发onDataBound事件。我也遇到了同样的问题,解决方法如下:
function onCancel(e) {
$("#GridName").data("kendoGrid").refresh();
}
//change grid color
function dataBound(e) {
$("#mygrid tbody tr").each(function(i) {
$(this).find("td:lt(9)").css("backgroundColor", '#000000');
});
}
我也遇到了这个问题,上面的解决方案对我不起作用。 但我找到了另一个解决方案,使用网格的Edit事件将事件处理程序附加到窗口的Deactivate事件 网格事件:
.Events(e => {
e.DataBound("onDataBound");
e.Edit("onEdit");
})
网格事件处理程序:
function onDataBound(e) {
//Conditional formatting on DataBound
formatGridRows();
}
function onEdit(e) {
//Bind deactivate event to the Popup window
e.container.data("kendoWindow").bind("deactivate", function () {
formatGridRows();
})
}
function formatGridRows() {
$("#Grid tbody tr").each(function () {
grid = $("#Grid").data("kendoGrid");
dataItem = grid.dataItem($(this));
//Conditionally format the current row
if (dataItem.Discontinued) {
$(this).find(":nth-child(3):first").css("background", "red");
}
})
}
以下是消息来源:
如果不想刷新网格,而是在事件完成后运行代码,则可以在取消事件中使用setTimeout()
function onGridCancel(e){
setTimeout(function() {
colorMyRowsBeutifully();
}, 0);
}
请参见Telerik的回答:
你好,莱利,我编辑了你的问题标题,以更好地反映你的问题。如果您觉得它是错误的,请随意回滚编辑。此外,您可能在此处遇到错误:
=>destory.Action(…
(destroy拼写错误)。好的,谢谢。@gitsitgosorry mate错误的代码。它应该是$(“#GridName”).data(“kendoGrid”).refresh();这在一定程度上起作用,因为它再次成功调用数据绑定事件,但它仍然保留(客户端)对行中的单元格所做的更改。解决了一个问题,但创建了另一个问题。