4

I have been looking all over for the answer and think I am missing something simple. I have a kendo grid where I want one of the columns to be a link to another page with the id as a route parameter. However, the value in the column cells are the bound values and are unchanged by my template. Any insights to this will be appreciated.

@(Html.Kendo().Grid((IEnumerable<ProviderAccess>)Model.Providers)
.Name("grants-grid")
.Columns(columns =>
{
    columns.Bound(a => a.ProviderName);
    columns.Bound(a => a.HasAccess);
    columns.Bound(a => a.ProviderId).ClientTemplate("#= toggleLink(data) #");
})
.Scrollable()
)

<script>
function toggleLink(access) {
    var action = '@Url.Action("Toggle", "Access")';

    var html = kendo.format("<a href='{0}/{1}'>Toggle...</a>",
        action,
        access.ProviderId
    );

    return html;
}
</script>
Jeff Lehmer
  • 241
  • 1
  • 5
  • 17

2 Answers2

10

ClientTemplate isn't using when Kendo Grid is binded to a dataSource on server side like your code.

You should use Template method of columns like below

 columns.Template(p => "<a href='..../Toggle/Access/" + p.ProviderId + "'>Click</a>");
pb2q
  • 58,613
  • 19
  • 146
  • 147
Yucel
  • 2,603
  • 5
  • 28
  • 40
4

dataSource.Server() will let you use a custom.template

dataSource.Ajax() will let you use ClientTemplate

Figuring that out was really frustrating... They are not interchangeable one of the other will work depending on ajax or Server

              <%: Html.Kendo().Grid((List<RadCarePlus.V2.Web.Models.GetMeSomeData>) ViewData["Mydata"])
                .Name("Grid")
                .Columns(columns =>
                {
                    columns.Template(c => "<a href='ImplementationDetails?EpisodeID=" + c.EpisodeID + "'>" + c.EpisodeID + "</a>").Title("Testing").Width(140);
                    //columns.Bound(c => c.EpisodeID).Width(140);
                    columns.Bound(c => c.AuthStatus).Width(190);
                    columns.Bound(c => c.CPTCode).Width(100);
                    columns.Bound(c => c.inscarrier).Width(110);
                    columns.Bound(c => c.CreatedOn).Width(160);
                    //columns.Template(c => "<a href='ImplementationDetails?EpisodeID=" + c.EpisodeID + "'>" + c.EpisodeID + "</a>");
                    //columns.Template(c => c.EpisodeID).Title("Testing").ClientTemplate("<a href='ImplementationDetails?EpisodeID=#= EpisodeID#'>#= EpisodeID #</a>");
                })
                .Pageable(pageable=> pageable.ButtonCount(5))
                .Sortable(sortable => sortable.AllowUnsort(false))
                .DataSource(dataSource => dataSource.Server().PageSize(5)
                )

            %>
Deathstalker
  • 794
  • 10
  • 8
  • Frustrating for sure. Thanks for clearing up why the accepted answer above of Template column type worked for me but the Kendo Document example of using ClientTemplate on a bound column appeared to work for them. – Piwaf May 18 '16 at 20:17