2016-12-28 82 views
0

我有一个kendo数据网格按列分组,默认情况下,我想编辑内联网格。我不希望用户按任何其他列进行分组。虽然默认分组工作正常,但更新事件不会被触发,控件也不会执行控制器的内联更新方法。你能检查我要去哪里吗?下面是代码:kendo datagrid更新事件不会在列上分组时触发

@(Html.Kendo().Grid(Model) 
    .Name("grdTimesheets") 
    .Columns(columns => 
    { 
     columns.Bound(p => p.EmployeeId).Hidden(true); 
     columns.Bound(p => p.FirstName); 
     columns.Bound(p => p.Monday.Hour).Title("Monday") 
      .EditorTemplateName("TimesheetMonday"); 
     columns.Command(command => 
     { 
      command.Edit(); 
      command.Destroy(); 
      command.Custom("Add").Text(" ").Click("AddNewTimesheet"); 
     }); 
    }) 
    .Editable(editable => editable.Mode(GridEditMode.InLine)) 
    .Pageable() 
    .Sortable() 
    .Groupable(false) 
    .Scrollable() 
    .DataSource(dataSource => dataSource 
     .Ajax() 
     .Model(model => 
     { 
      model.Id(p => p.EmployeeId); 
      model.Field(p => p.FirstName).Editable(false); 
     }) 
     .PageSize(20) 
     .Update(update => update.Action("EditingInline_Update", "Timesheet")) 
     .Destroy(destroy => destroy.Action("EditingInline_Destroy", "Timesheet")) 
     .Group(d=>d.Add(f=>f.FirstName)) 
    ) 

如果我注释掉最后一行 “集团(d => d.Add(F => f.FirstName))”,一切工作正常,但默认分组熄灭。

回答

0

我知道它的答案有点晚,但我会在这里留下这个情况,以防其他人遇到同样的问题。一旦按任意列分组,网格将不会触发“.Update(update => update.Action(”EditingInline_Update“,”Timesheet“))”。为了解决这个问题,您需要为网格添加OnEditEvent,并在javascript函数中添加一个事件到文本框/下拉列表或任何您拥有的控件。下面的示例:

.Events(事件=> events.Edit( “grid_edit”)),这是在视图

的javascript:

function grid_edit(e) { 
    var grid = $('#grid').data('kendoGrid'); 
    var cell = e.container; 
    var area = cell.find("textarea") 

    area.on("blur", function() { 
     // update ur entries here 
     var areaVal = cell.find("textarea").val(); // this is the new value 
     // call some ajax to update the value and in the success call grid.dataSource.sync(); to refresh the grid 
    });} 

你也将需要删除您.Update( )的数据源,因为它不再需要。