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

How to set SubGrid data binding conditional?

6 Answers 431 Views
Grid
This is a migrated thread and some comments may be shown as answers.
HSO
Top achievements
Rank 2
HSO asked on 02 Apr 2013, 03:52 PM
Hello:

I've followed the demo to setup the master/detail grids (or hierarchy grids), they works fine as intended.
However I'd like to make improvement by asking how to make SubGrid data binding conditional.

By default if the MasterGrid returned 10 rows, then the data binding to the SubGrid, which is the url to Controller/Action, were called 10 times, with each one pass in the different ID from MasterGrid.

In my case I only need to call the data bind to SubGrid when a value in MasterGrid has met the requirement.
i.e. for each row of MasterGrid returned, only if the column MyFlag=1, then I need to call the SubGrid.
So out of 10 rows turned, if only 3 rows has MyFlag=1, then the data call to SubGrid only need to be 3 times, instead of 10.

I am not sure how to do that, please advise.

Thank you,

9 hours ago (Link to this post)


Hello:

I've followed the demo to setup the master/detail grids (or hierarchy grids), they works fine as intended.
However I'd like to make improvement by asking how to make SubGrid data binding conditional.

By default if the MasterGrid returned 10 rows, then the data binding to the SubGrid, which is the url to Controller/Action, were called 10 times, with each one pass in the different ID from MasterGrid.

In my case I only need to call the data bind to SubGrid when a value in MasterGrid has met the requirement.
i.e. for each row of MasterGrid returned, only if the column MyFlag=1, then I need to call the SubGrid.
So out of 10 rows turned, if only 3 rows has MyFlag=1, then the data call to SubGrid only need to be 3 times, instead of 10.

I am not sure how to do that, please advise.

Thank you,

9 hours ago (Link to this post)


Hello:

I've followed the demo to setup the master/detail grids (or hierarchy grids), they works fine as intended.
However I'd like to make improvement by asking how to make SubGrid data binding conditional.

By default if the MasterGrid returned 10 rows, then the data binding to the SubGrid, which is the url to Controller/Action, were called 10 times, with each one pass in the different ID from MasterGrid.

In my case I only need to call the data bind to SubGrid when a value in MasterGrid has met the requirement.
i.e. for each row of MasterGrid returned, only if the column MyFlag=1, then I need to call the SubGrid.
So out of 10 rows turned, if only 3 rows has MyFlag=1, then the data call to SubGrid only need to be 3 times, instead of 10.

I am not sure how to do that, please advise.

Thank you,

6 Answers, 1 is accepted

Sort by
0
Accepted
Jayesh Goyani
Top achievements
Rank 2
answered on 03 Apr 2013, 12:09 PM
Hello,

<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.

 
Thanks,
Jayesh Goyani
0
HSO
Top achievements
Rank 2
answered on 03 Apr 2013, 02:38 PM
You are awesome! it works!

thank you so much!
0
Luis
Top achievements
Rank 1
answered on 13 May 2015, 03:13 PM
Hello is there a way to delete the arrow on the left?
0
Iliana Dyankova
Telerik team
answered on 15 May 2015, 02:10 PM

Hi Luis,

The following CSS rule should help to remove the arrows: 

.k-grid .k-hierarchy-cell .k-icon {
    display: none;
}

 

Regards,
Iliana Nikolova
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Domenico
Top achievements
Rank 1
answered on 17 Mar 2016, 03:33 PM
Any way to conditional remove the arrow?
0
Iliana Dyankova
Telerik team
answered on 21 Mar 2016, 04:10 PM
Hi Domenico,

For this scenario you should use custom JavaScript logic in the Grid's dataBound event. To hide / show the icons you could use the jQuery hide / show methods.

Regards,
Iliana Nikolova
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
Grid
Asked by
HSO
Top achievements
Rank 2
Answers by
Jayesh Goyani
Top achievements
Rank 2
HSO
Top achievements
Rank 2
Luis
Top achievements
Rank 1
Iliana Dyankova
Telerik team
Domenico
Top achievements
Rank 1
Share this question
or