2014-03-03 44 views
0

我一直在使用內聯刪除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調用一個控制器方法:

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 
    } 
} 

如何獲得該行的價值和檢查的條件?

回答

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

}) 

selectedItem屬性將有你的模型的所有屬性