Template Columns not displaying data

5 posts, 1 answers
  1. Uday
    Uday avatar
    17 posts
    Member since:
    Jun 2014

    Posted 07 Jul 2014 Link to this post

    Hi, 

    I am trying to display the a hyperlink for one of the columns in my Grid. I added a template column as per the documentation and it is not displaying any content.

    I check the server response. It does return the data. The column is disappearing on the client side once tied to the Grid.

    Below is the snippet from MVC Grid examples (local-data-binding). I modified a bit to add a template column. You can easily reproduce this by adding the first column to the example at Grid at local-data-binding example.

    @model IEnumerable<Kendo.Mvc.Examples.Models.ProductViewModel>
     
    @(Html.Kendo().Grid(Model)
        .Name("Grid")
        .Columns(columns =>
        {
            columns.Template(@<text>
                @Html.ActionLink(item.ProductName, "Local_Data_Binding", "Grid", new { id = item.ProductName }, null)
            </text>).Title("Company Name");
            columns.Bound(p => p.ProductName).Title("Product Name");
            columns.Bound(p => p.UnitPrice).Title("Unit Price").Width(130);
            columns.Bound(p => p.UnitsInStock).Title("Units In Stock").Width(130);
            columns.Bound(p => p.Discontinued).Width(130);
        })
        .Pageable()
        .Sortable()
        .Scrollable(scr=>scr.Height(430))
        .Filterable()
        .DataSource(dataSource => dataSource
            .Ajax()
            .PageSize(20)
            .ServerOperation(false)
         )
    )

    Any suggestions. Looks like this is working for some people.

    Thank You,
  2. Answer
    Dimiter Madjarov
    Admin
    Dimiter Madjarov avatar
    2153 posts

    Posted 08 Jul 2014 Link to this post

    Hello Uday,


    The reason for the issue is that the current Grid is using an Ajax Bound dataSource, which requires client templates, instead of server ones.
    E.g.
    columns.Template(@<text></text>).ClientTemplate("my template");

    You could take a look at the following page for additional information about displaying an action link in a client template.

    I wish you a great day!

    Regards,
    Dimiter Madjarov
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  3. UI for ASP.NET MVC is VS 2017 Ready
  4. Uday
    Uday avatar
    17 posts
    Member since:
    Jun 2014

    Posted 08 Jul 2014 in reply to Dimiter Madjarov Link to this post

    Thank You. It worked.
  5. Pawel Ch
    Pawel Ch avatar
    4 posts
    Member since:
    May 2015

    Posted 22 Jan in reply to Dimiter Madjarov Link to this post

    Hi Dimiter

    Answer you provided is proper and it works in this case (Ajax binding). It helped me to solve small problem with client side binding. But example of Ajax binding on the page you refer to is misleading.

    On the page there is a fragment relaed to AJAX as follows:

    For ajax bound grids the ClientTemplate method should be used.
     
    Example - action link in Ajax bound Grid column
     
    columns.Bound(p => p.ProductID).ClientTemplate("<a href='" +Url.Action("ProductDetails", "Product") +"/#= ProductID #'" +">Show Product Details</a>"); 

    but this code doesnt work.

    For Ajax bound datagrid client template column code should be like below (I checked both ) :

    columns.Template(@<text></text>).ClientTemplate(
    "<a href='" +
        Url.Action("ProductDetails", "Product") +
        "/#= ProductID #'" +
    ">Show Product #= ProductID #</a>"
        ).Title("Action");

     

  6. Dimiter Madjarov
    Admin
    Dimiter Madjarov avatar
    2153 posts

    Posted 27 Jan Link to this post

    Hello Pawel,

    Both of the provided sample templates will work in an Ajax bound Grid. The first one is for a column bound to a model property. The second one is a pure template column, which is not bound to a property i.e. it cannot be filtered, sorted etc.

    Regards,
    Dimiter Madjarov
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top
UI for ASP.NET MVC is VS 2017 Ready