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

get item from kendo child grid

1 Answer 59 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Vasiliy
Top achievements
Rank 1
Vasiliy asked on 24 Nov 2016, 09:34 AM
Having Hierarchy grid, trying to add custom client template with <a href> and item with it. But, don't know how can i get child item. For ex. on parent grid i'm getting item like: 

    .Columns(columns =>
              {
                  columns.Template(e => { }).ClientTemplate("<strong><a  href='" + Url.Action("Details", "Types") + "#= Id #'> #= Name #  </a></strong>").Title("Type Name").Width("30%");

How can I make this the same for child grid? 

    .Name("grid_#=Id#")
                .Columns(columns =>
                {
                    columns.Bound(e => e.Name).Title("SubType Name").ClientTemplate("<a href='" + Url.Action("Details", "Types") + "#= e.data.Id #'>#= e.data.Name #</a>");

If I will use like: `#= data.Name #` it will display parent data.

1 Answer, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 28 Nov 2016, 09:25 AM
Hi Vasiliy,

Yes, you will need to use escaping logic for the inner grid:
http://docs.telerik.com/kendo-ui/framework/templates/overview#inline-vs-external-templates

Condition:
http://docs.telerik.com/kendo-ui/aspnet-mvc/helpers/grid/faq#how-to-apply-conditional-logic-in-column-client-templates

This is for master value, for example FirstName:
Copy Code
columns.Bound(o => o.OrderID).ClientTemplate(
     "# if (ProductName != null) { #" +
         "#: ProductName #" +
     "# } else { #" +
         "Error" +
     "# } #");

If you want to use the detail value, however, you will need to use the approach below:
Copy Code
columns.Bound(o => o.ShipName).ClientTemplate(
    "\\#: getShipName(ShipName) \\#"
    );
JavaScript:
Copy Code
function getShipName(shipName) {
    if (shipName != null) {
        return shipName;
    }
    else {
        return "error";
    }
}

I hope this will prove helpful.


Regards,
Eyup
Telerik by Progress
Telerik UI for ASP.NET MVC is ready for Visual Studio 2017 RC! Learn more.
Tags
Grid
Asked by
Vasiliy
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Share this question
or