This is a migrated thread and some comments may be shown as answers.

Can't get Column value of a grid hierarchy

1 Answer 204 Views
Grid
This is a migrated thread and some comments may be shown as answers.
JP
Top achievements
Rank 1
JP asked on 15 Apr 2015, 02:57 PM
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>

1 Answer, 1 is accepted

Sort by
0
Nikolay Rusev
Telerik team
answered on 17 Apr 2015, 06:57 AM

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.

 
Tags
Grid
Asked by
JP
Top achievements
Rank 1
Answers by
Nikolay Rusev
Telerik team
Share this question
or