如何在内联删除之前获取Kendo Grid中的行值

时间:2014-03-03 06:25:36

标签: kendo-ui kendo-grid

我一直在使用Kendo Grid的内联删除,但我需要检查条件然后删除行。

@(Html.Kendo().Grid<DocumentSearchViewModel>()
          .Name("documentListGrid")
          .Columns(columns =>
              {
                  columns.Bound(model => model.AgentID).Title("Agent Code").Width("15%");
                  columns.Bound(model => model.DocumentSecurityID).ClientTemplate("#if(data.AllowToView==1)" +
                                                                                    "{ #<a class='lnkDocument'  href='" + Url.Action("Download", "Document", new { fileName = "#=ScanFile#", fileLocation = "#=VC01#", batchTime = "#=BatchTime#", documentNumber = "#=CaseID#" }) + "' target='documentViewer'>#=data.BatchDescription#</a>#" +
                                                                                  " " + " }" +
                                                                                  "else{#<a class='disable-link' onclick='return Response();'>#=data.BatchDescription#</a> #}#").Title("Description").Width("30%");
                  columns.Bound(model => model.CaseID).Width("10%").Title("Case#");
                  columns.Bound(model => model.DocumentGroupID).Width("15%").Title("Group ID");
                  columns.Bound(model => model.BatchNumber).Width("10%").Title("Batch#");
                  columns.Bound(model => model.CreatedDate).Width("10%").Format(UI.DocumentSearchDateFormat).Title("Created Date");
                  columns.Command(command => command.Custom("Remove").Click("deleteRow"));
                  columns.Bound(model => model.DocSystemID).Visible(false);

              })
          .Pageable()

          .Sortable(sortable => sortable.AllowUnsort(false))
          .DataSource(dataSource => dataSource
                                        .Ajax()
                                        .ServerOperation(false)
                                           .Model(model => model.Id(p => p.CaseID))

                                        .Read(read => read.Action(WorkflowControllers.Document.ActionNames.GetDocumentList, WorkflowControllers.Document.Name, new { caseId = @Model.CaseID }))
                                        .Events(ev => ev.Change("OnGridChange"))

          ).AutoBind(true).Events(events => events.DataBound("DisplayDocument"))
          )

调用javascript函数,该函数将使用Ajax调用调用Controller方法:

function deleteRow(e) {
    e.preventDefault ? e.preventDefault() : e.returnValue = false;
    var grid = $("#documentListGrid").data("kendoGrid");
    if (confirm("Are you sure you want to delete the selected record(s)?")) {

        grid.removeRow($(e.target).closest("tr")); 
    } else {
        // cancel button is clicked
    }
}

如何获取行的值并检查条件?

1 个答案:

答案 0 :(得分:0)

 $('#Grid').click(function () {
    var gview = $(this).data("kendoGrid");
    var selectedItem = gview.dataItem(gview.select());
    var Guid = selectedItem.YourPropertName;

})

selectedItem将拥有模型的所有属性