Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

kendoui ClientTemplate in Grid not working in asp.net mvc 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>
like image 455
Jeff Lehmer Avatar asked Dec 08 '22 14:12

Jeff Lehmer


2 Answers

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>");
like image 128
Yucel Avatar answered Dec 11 '22 05:12

Yucel


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

            %>
like image 31
Deathstalker Avatar answered Dec 11 '22 04:12

Deathstalker