Question

I am trying to figure out how to get the data from a cell of the row I have selected. I need it to be a parameter in my URL.Action. Is there a way to achieve this? If so, how?

Below is the code.

@(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()

        )
Was it helpful?

Solution

You can access selected cell information from the following JQuery code.

$('#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")

Take a look at the following post for getting the value to your URL.Action, it requires using FormCollection.

reading hidden field value in action?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top