2014-05-08 37 views
0

我想弄清楚如何從我選擇的行的單元格中獲取數據。我需要它是我的URL.Action中的一個參數。有沒有辦法做到這一點?如果是這樣,怎麼樣?Kendo UI Grid將單元數據中的參數傳遞給

以下是代碼。

@(Html.Kendo().Grid(Model.dailyLogEventList) 
     .Name("dailyLogGrid") 
     .HtmlAttributes(new { style = "height: 360px" }) 
     .DataSource(dataSource => dataSource 
     .Ajax() 
     .PageSize(8) 
     .Read(read => read.Action("DailyLogList_Read", "DailyLog")) 
     ) 
.Columns(columns => 
{ 
    columns.Bound(x => x.IsEventRequired) 
     .ClientTemplate("<a href='" + Url.Action("index", "IncidentReport", new { area = "DailyLog" }) 
     + "'>" + "#= IsEventRequired ? '<img src=\"/Images/icon_edit.gif\" />' : '' #" + "</a>") 
     .Width(25) 
     .Title("") 
     .Filterable(false); 
    columns.Bound(x => x.LogId).Width(25).Title("Id"); 
    columns.Bound(x => x.StartDate).Title("Started").Format("{0:MM/dd/yyyy HH:mm}").Width(60).Sortable(true); 
    columns.Bound(x => x.EventDescription).Title("Event").Width(120).Filterable(filterable => filterable.UI("eventDescFilter")); 
    columns.Bound(x => x.Comments).Title("Comments").Width(200); 
    columns.Bound(x => x.RespondingOfficers).Title("Officer(s)").Width(190); 
    columns.Command(command => command.Custom("Edit").Click("loadDataForEdit")).Width(20) 
     .HtmlAttributes(new { style = "text-decoration:none; text-align:right;" }) 
     ; 

}) 
    .Pageable() 
    .Selectable(s => s.Mode(GridSelectionMode.Single)) 
    .Filterable() 

     ) 

回答

0

您可以從以下JQuery代碼中訪問選定的單元格信息。

$('#dailyLogGrid).click(function() { 
     var gview = $(this).data("kendoGrid"); 
     var selectedItem = gview.dataItem(gview.select()); 
     var cellValue= selectedItem.PropertyName; 
     $("#HiddenField").val(cellValue); //Store value in hidden field 
    }) 

    @Html.Hidden("HiddenField") 

看看下面的職位所獲得的價值您URL.Action,它需要使用的FormCollection。

reading hidden field value in action?

+0

謝謝。這是比我想出的更好的解決方案。 – jeffkenn