Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kendo Grid DetailTemplate, condition expression of accessing SubGrid value

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

like image 253
smeagull Avatar asked Mar 24 '23 04:03

smeagull


1 Answers

# in some kendo template is used for parent property (like you use for the name : gridSubEle_#=EleID#, but for some child property, you have to escape the # with \\ :

         cols.Bound(e => e.Rating)      
             .ClientTemplate("<input type='checkbox' value='1' " +
                            "\\#if(Rating==1){\\#checked='checked'\\#}\\# />" );
like image 141
Samuel Caillerie Avatar answered Apr 06 '23 13:04

Samuel Caillerie