如何防止取消事件更改网格行颜色?

Lyl*_*yly 2 kendo-ui kendo-grid kendo-asp.net-mvc

我搜索数据然后绑定到我的网格.在网格databound事件中,我根据单元格的值更改行背景颜色.这很好用.但是当我单击网格中的"编辑"按钮然后单击"取消"按钮时,网格不再具有背景颜色集.我试图在databound事件中调用该事件Cancel,但它不起作用.如何防止取消事件更改网格颜色?

   @(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"))
            ))
Run Code Online (Sandbox Code Playgroud)

数据绑定事件

  //change grid color
   function dataBound(e) {

        $("#mygrid tbody tr").each(function(i) {
          $(this).find("td:lt(9)").css("backgroundColor", '#000000');
        });
    }
Run Code Online (Sandbox Code Playgroud)

取消活动

     //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();
}
Run Code Online (Sandbox Code Playgroud)

flo*_*wer 6

您可以grid.cancelRow()在中使用cancel enent,然后刷新网格.


Sha*_*haz 6

只需刷新取消事件中的网格即可.它将再次触发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');
    });
}
Run Code Online (Sandbox Code Playgroud)