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

Grid DetailTemplate, condition expression of accessing SubGrid value

2 Answers 135 Views
Grid
This is a migrated thread and some comments may be shown as answers.
HSO
Top achievements
Rank 2
HSO asked on 26 Apr 2013, 03:53 AM
Hello:

I have a Master/Child grid structure like so:

Parent Grid:
 @(Html.Kendo().Grid<ElementViewModel>()
.Name("gridEle")
.Columns(cols =>
{
    cols.Bound(e => e.EleNum)
})
.DataSource(dataSource => dataSource
    .Ajax()
    .Read(read => read.Action("GetElements", "Rating", pi))   
)
.ClientDetailTemplateId("tempSubEle")          
)

Child Grid as DetailTemplate:


<script id="tempSubEle" type="text/kendo-tmpl">
 
@(Html.Kendo().Grid<SubElementViewModel>()
.Name("gridSubEle_#=EleID#")
.Columns(cols =>
{
    cols.Bound(e => e.Rating)      
        .ClientTemplate("<input type='checkbox' value='1' " +
                        "#if(Rating==1){#checked='checked'#}# />" );
})
.DataSource(dataSource => dataSource
            .Ajax()
            .Read(read => read.Action("GetSubElementsByElementID", "Rating", new { eID = "#= EleID #" }))
)
.ToClientTemplate()
)
    </script>
The Problem:

I have a #if{# ... #}# statement in the column ClientTemplate, however the Rating value is from the Parent Grid not the current Child Grid (Parent Grid happen has a column also named 'Rating'), to prove that it is from Parent Grid,  if I change Rating to a column that only exists in the Child grid, i.e. SubEleID, it gives error at browser, saying that SubEleID is not found.

The Question:
so what is the syntax for Rating gets the Child Grid value?
just for the sake of trying, I even tried: data.Rating, or $(this).Rating, none worked.

Please advise,
Thank you

2 Answers, 1 is accepted

Sort by
0
Accepted
Nikolay Rusev
Telerik team
answered on 26 Apr 2013, 07:26 AM
Hello Jason,

As the detail Grid is inside client template all other client templates /i.e column ClientTemplate/ must escape the `#` symbols.

In your case the template for the column will become as this:

cols.Bound(e => e.Rating)     
 .ClientTemplate("<input type='checkbox' value='1' " +
  "\\#if(SubEleID==1){\\#checked='checked'\\#}\\# />" );

Regards,
Nikolay Rusev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
HSO
Top achievements
Rank 2
answered on 26 Apr 2013, 08:00 AM
thank you, works!
Tags
Grid
Asked by
HSO
Top achievements
Rank 2
Answers by
Nikolay Rusev
Telerik team
HSO
Top achievements
Rank 2
Share this question
or