Can't get Column value of a grid hierarchy

2 posts, 0 answers
  1. JP
    JP avatar
    3 posts
    Member since:
    Jan 2015

    Posted 15 Apr 2015 Link to this post

    Hi everyone,

    I've created a  Grid Hierarchy here..I was able to get the column values from my Parent Grid(CustomerGrid) to use it on a ClientTemplate for example 

    (@Html.ActionLink("Add Order", "AddOrder", "Customer", new { customerId = "#= CustomerId#" }, null).ToHtmlString()). 

    But when I'm trying to adapt this kind of code, now getting the customerOrderId field from my Child Grid and use it on my ClientTemplate for example 

    (@Html.ActionLink(AmsStrings.LabelEditAmendment, "EditOrder", "CustomerOrder", new { orderId = "#= OrderId#" }, null).ToHtmlString())

     I've retrieved nothing from here.The later code was used inside the Child Grid? What is wrong with my code? Why is it column values from my Parent Grid are available for use on my ClientTemplate while column values on my Child Grid are not available for use? 

     

    @(Html.Kendo().Grid<customerviewmodel>
    ()
    .Name("CustomerGrid")
    .Columns(columns =>
    {
    columns.Bound(item => item.CustomerId).Hidden(true);
    columns.Bound(item => item.Name);
    columns.Template(t => { })
    .Title("")
    .Width(120)
    .ClientTemplate("<div class='btn-group'>
        " +
        "<a class='btn btn-default btn-sm dropdown-toggle' data-toggle='dropdown'> Action <span class='caret'></span></a>" +
        "<ul class='dropdown-menu'>
            " +
            "
            <li>" + (@Html.ActionLink("Add Order", "AddOrder", "Customer", new { customerId = "#= CustomerId#" }, null).ToHtmlString()) + "</li>" +
            "
        </ul>
    </div>");
     
    })
    .Selectable(selectable =>
    {
    selectable.Enabled(true);
    selectable.Mode(GridSelectionMode.Single);
    })
    .ClientDetailTemplateId("template")
    .DataSource(datasource => datasource.Ajax()
    .Model(model =>
    {
    model.Id(m => m.CustomerId);
    })
    .Read(read => read.Action("CustomerDataSource", "Customer")))
    .Sortable())
     
     
     
    <script id="template" type="text/x-kendo-template">
        @(Html.Kendo().Grid
        <CustomerOrderViewModel>
            ()
            .Name("grid_#=CustomerId#")
            .Columns(columns =>
            {
            columns.Bound(item => item.OrderId).Hidden(true);
            columns.Bound(item => item.OrderName);
            columns.Template(@<text></text>)
            .Title("")
            .Width(100)
            .ClientTemplate("<div class='btn-group'>
                " +
                "<a class='btn btn-default btn-sm dropdown-toggle' data-toggle='dropdown'>Action<span class='caret'></span></a>" +
                "<ul class='dropdown-menu'>
                    " +
                    "
                    <li>" + (@Html.ActionLink("Edit", "EditOrder", "CustomerOrder", new { orderId = "#= OrderId#" }, null).ToHtmlString()) + "</li>" +
                    "
                    <li>" + (@Html.ActionLink("View", "ViewOrder", "CustomerOrder", new { orderId = "#= OrderId#" }, null).ToHtmlString()) + "</li>" +
     
                    "
                </ul>
            </div>");
     
            })
     
            .Editable(editable => editable.Enabled(false))
            .Sortable()
            .Selectable(selectable =>
            {
            selectable.Enabled(true);
            selectable.Mode(GridSelectionMode.Single);
            })
            .DataSource(datasource => datasource
            .Ajax()
            .ServerOperation(false)
            .PageSize(5)
            .Model(model => model.Id(p => p.OrderId))
            .Read(read => read.Action("CustomerOrderDataSource", "CustomerOrder", new { customerOrderId = "#=customerId#" })))
            .ToClientTemplate())
     
     
     
    </script>
  2. Nikolay Rusev
    Admin
    Nikolay Rusev avatar
    2289 posts

    Posted 17 Apr 2015 Link to this post

    Hello Peevee,

    When you define template in for detail grid you **must** escape the # symbols. Otherwise the will be evaluated as part of the parent grid.

    That said the ClientTemplate of the detail grid should become as follows: `(@Html.ActionLink(AmsStrings.LabelEditAmendment, "EditOrder""CustomerOrder"new { orderId = "\\#= OrderId\\#" }, null).ToHtmlString())`

    Regards,
    Nikolay Rusev
    Telerik
     

    See What's Next in App Development. Register for TelerikNEXT.

     
Back to Top