Grid DetailTemplate, condition expression of accessing SubGrid value

3 posts, 1 answers
  1. HSO
    HSO avatar
    17 posts
    Member since:
    Sep 2006

    Posted 25 Apr 2013 Link to this post

    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. Answer
    Nikolay Rusev
    Admin
    Nikolay Rusev avatar
    2289 posts

    Posted 26 Apr 2013 Link to this post

    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!
  3. HSO
    HSO avatar
    17 posts
    Member since:
    Sep 2006

    Posted 26 Apr 2013 Link to this post

    thank you, works!
Back to Top