Client Detail Template Conditional On Parent Row

2 posts, 0 answers
  1. malcolm
    malcolm avatar
    1 posts
    Member since:
    Jun 2015

    Posted 19 Sep Link to this post

    I have a grid of customer transactions and a child detail grid which expands the transaction into line info for the transaction.  This works well but I only want the child detail grid to be available for rows on the parent with a certain transaction type id.

    Is this possible?

  2. Maria Ilieva
    Admin
    Maria Ilieva avatar
    4017 posts

    Posted 21 Sep Link to this post

    Hi Malcolm,

    You can use the following appraoch:

    <div>
        @(Html.Kendo().Grid<MvcApplication1.Models.TestModels>()
            .Name("Grid")
            .Columns(columns =>
            {
                columns.Bound(p => p.ID);
                columns.Bound(p => p.Name);
            })
            .Filterable()
            .Sortable()
                      .ClientDetailTemplateId("template")
            .DataSource(dataSource => dataSource
                .Ajax()
     
                        .Read(read => read.Action("Grid_Read", "Home"))
                 .Model(model => { model.Id(p => p.ID); })
            )
        )
    </div>
    <script id="template" type="text/kendo-tmpl">
     #if(ID > 2){#
        @(Html.Kendo().Grid<MvcApplication1.Models.TestFullCalender>()
                .Name("grid_#=ID#")
                .Columns(columns =>
                {
                    columns.Bound(o => o.id).Width(70);
                    columns.Bound(o => o.title).Width(70);
                })
                .DataSource(dataSource => dataSource
                    .Ajax()
                    .PageSize(5)
                    .Read(read => read.Action("Grid_ReadChild", "Home", new { ID = "#=ID#" }))
                )
                .Pageable()
                .Sortable()
                .ToClientTemplate()
        )
        #}#
    </script>

    public ActionResult Grid_Read([DataSourceRequest] DataSourceRequest request)
            {
                List<TestModels> models = new List<TestModels>();
     
                for (int i = 1; i < 6; i++)
                {
     
                    TestModels model = new TestModels();
                    model.ID = i;
                    model.Name = "Name" + i;
                    models.Add(model);
     
                }
     
                return Json(models.ToDataSourceResult(request));
            }
     
            public ActionResult Grid_ReadChild([DataSourceRequest] DataSourceRequest request, int ID)
            {
                List<TestFullCalender> models = new List<TestFullCalender>();
     
                for (int i = 1; i < 6; i++)
                {
     
                    TestFullCalender model = new TestFullCalender();
                    model.id = i.ToString();
                    model.title = "title" + i;
                    models.Add(model);
     
                }
     
                return Json(models.ToDataSourceResult(request));
            }
    public class TestModels
    {
        public int ID { get; set; }
        public string Name { get; set; }
        public bool IsActive { get; set; }
        public int FID { get; set; }
    }
     
    public class TestFullCalender
    {
        public string id { get; set; }
        public string title { get; set; }
    }

    It show Subgrid only when ID is greater than 2.

    I hope this helps.


    Regards,
    Maria Ilieva
    Telerik by Progress
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. UI for ASP.NET MVC is VS 2017 Ready
Back to Top