Kendo Grid changing a column Text - MVC 5 , Razor

I want to remove/hide the hyperlink of a cell/row based on a condition, I'm using Kendo UI for MVC with Razor.

The first column is bound with "View" hyperlink. Which I need to be controlled (remove/hide) based on the values of another column in the same grid i.e. the 2nd column "LastName".

i.e. when the item bound to the grid need to do the below logic.

If current [LastName] == previous [LastName] then hide View hyperlink, so i will have only one view link for the users with same last name.

Appreciate any help or suggestions. Below is my code to ender the grid.

@model IEnumerable<EDM2_UI.Models.ReportsViewModel>
@(Html.Kendo().Grid(Model)
.Name("advancedGrid")
.Columns(columns =>
{

    columns.Bound("ReportID").ClientTemplate("<a href='" + Url.Action("Index", "GRECandidateReport") + "/Index/#= ReportID #'" + ">View</a>").Title("").Width(50).Filterable(false);                
    columns.Bound(p => p.LastName).Title("Last Name").Width(130);
    columns.Bound(p => p.TestName).Title("Test Name").Width(130).Filterable(false);
    columns.Bound(p => p.TestDate).Width(130);

})
.Pageable()
.Sortable()
.Scrollable(scr => scr.Height(500))
.Resizable(resize => resize.Columns(true)) 
.Filterable()
.Groupable()
.DataSource(dataSource => dataSource
    .Ajax()
    .PageSize(100)
    .ServerOperation(false)
    )
)

Upvotes: 3

Views: 2382

Answers (1)

Andrew Merritt
Andrew Merritt

Reputation: 307

You should be able to put a conditional statement inside the ClientTemplate. First you need to define the URL in the view model and leave it blank where it is not needed. Then something like this should work in your views:

.ClientTemplate("# if (ReportIDLink != '') { # <a href='#= ReportIDLink # '>View</a> # } else { # <div>#= ReportID #</div> # } #")

Upvotes: 3

Related Questions