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

Is there a way to directly use properties of the parent grid in the child grid?

2 Answers 228 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Stephen
Top achievements
Rank 1
Stephen asked on 05 Aug 2015, 06:39 PM

In the below hierarchical grids, which include the parent and child grids. Show or hide some of the columns in the child grid is based on the values presented in the parent grid. Right now, it's done by using events, as indicated by the following codes. 

  @(Html.Kendo().Grid<Payroll.Models.PayrollAuthorizationByDepartmentModel>().Name("parentGrid")
            .Columns(columns =>
        {
            columns.Bound(dataSource => dataSource.DepartmentName).Title("Department Name");
            columns.Bound(dataSource => dataSource.TotalHours).Title("Hours");
            columns.Bound(dataSource => dataSource.TotalVacationHours).Title("Vacation Hours");
            columns.Bound(dataSource => dataSource.TotalBereavementHours).Title("Bereavement yHours");
            columns.Bound(dataSource => dataSource.TotalJuryDutyHours).Title("Jury Duty Hours");
            columns.Bound(dataSource => dataSource.TotalHolidayHours).Title("Holiday Hours");
            columns.Bound(dataSource => dataSource.TotalPhamacistHours).Title("Phamacist Hours");
        })
       .DataSource(dataSource => dataSource
                              .Ajax()
                              .Aggregates(aggregates =>
                              .Read(read => read.Action("Location_Authorization_Read", "Authorize", new { locationId ="#=LocationId#"))
                              .PageSize(10)
                              .ServerOperation(false)
                             .Sort(sort => sort.Add("LocationId").Ascending())
        )
            .ClientDetailTemplateId("template")
            .Events(events => events.DetailExpand("expandParentGrid"))
            .Events(events => events.DataBound("onDataBound"))
                  )

<script id="template" type="text/kendo-tmpl">
    @(Html.Kendo().Grid<Payroll.Models.PayrollAuthorizationByEmployeeModel>()
                        .Name("childGridAuthorizationByEmployee_#=DepartmentId#")
                        .Columns(columns =>
                        {
                                    columns.Bound(dataSource => dataSource.EmployeeId).Title("Emp. No");                           
                                    columns.Bound(dataSource => dataSource.EmployeeName).Title("Emp. Name");                           
                                    columns.Bound(e => e.Hours).Title("Hours"));   
                                    columns.Bound(e => e.VacationHours).Title("Vac."));
                                    columns.Bound(e => e.JuryDutyHours).Title("Jury"));
                                    columns.Bound(e => e.HolidayPayHours).Title("Holiday"));
                                    columns.Bound(e => e.BereavementPayHours).Title("Bereav."));
                                    columns.Bound(e => e.PhamacistHours).Title("Pharm. "));                                  
                                })
                        .DataSource(dataSource => dataSource
                        .Ajax()                               
                        .Read(read => read.Action("AuthorizationByEmployee_Read", "Authorize", new { locationId = "#=LocationId#", departmentId ="#=DepartmentId#"}))                                                  
                        .Events(events => events.DataBound("onDataBoundOfChildGrid"))
                        .ToClientTemplate())
</script>

<script type="text/javascript">

 function onDataBound(e) {
        this.expandRow(this.tbody.find("tr.k-master-row"));
    }
function expandParentGrid(e){
        var dataItem = e.sender.dataItem(e.masterRow);
        if (!(dataItem.TotalVacationHours) > 0) {
            $("#childGridAuthorizationByEmployee_" + dataItem.DepartmentId).data("kendoGrid").hideColumn("VacationHours");
        }
        if (!(dataItem.TotalJuryDutyHours) > 0) {
            $("#childGridAuthorizationByEmployee_" + dataItem.DepartmentId).data("kendoGrid").hideColumn("JuryDutyHours");
        }
        if (!(dataItem.TotalHolidayPayHours) > 0) {
            $("#childGridAuthorizationByEmployee_" + dataItem.DepartmentId).data("kendoGrid").hideColumn("HolidayPayHours");
        }
        if (!(dataItem.TotalBereavementPayHours) > 0) {
            $("#childGridAuthorizationByEmployee_" + dataItem.DepartmentId).data("kendoGrid").hideColumn("BereavementPayHours");
        }
        if (!(dataItem.TotalPharmacistHours) > 0) {
            $("#childGridAuthorizationByEmployee_" + dataItem.DepartmentId).data("kendoGrid").hideColumn("PhamacistHours");
        }
    }

</script>

I was wondering if there is a way to directly use properties of the parent grid in the child grid. Something like this:

<script id="template" type="text/kendo-tmpl">
    @(Html.Kendo().Grid<Payroll.Models.PayrollAuthorizationByEmployeeModel>()
                        .Name("childGridAuthorizationByEmployee_#=DepartmentId#")
                        .Columns(columns =>
                        {
                                    columns.Bound(dataSource => dataSource.EmployeeId).Title("Emp. No");                           
                                    columns.Bound(dataSource => dataSource.EmployeeName).Title("Emp. Name");                           
                                    columns.Bound(e => e.Hours).Title("Hours")); 
if(#=******.TotalVacationHours# >0)  {
                                    columns.Bound(e => e.VacationHours).Title("Vac."));
}
if(#=*****.TotalJuryDutyHours# >0) {
                                    columns.Bound(e => e.JuryDutyHours).Title("Jury"));
}
                                    columns.Bound(e => e.HolidayPayHours).Title("Holiday"));
                                    columns.Bound(e => e.BereavementPayHours).Title("Bereav."));
                                    columns.Bound(e => e.PhamacistHours).Title("Pharm. "));                                  
                                })
                        .DataSource(dataSource => dataSource
                        .Ajax()                               
                        .Read(read => read.Action("AuthorizationByEmployee_Read", "Authorize", new { locationId = "#=LocationId#", departmentId ="#=DepartmentId#"}))                                                  
                        .Events(events => events.DataBound("onDataBoundOfChildGrid"))
                        .ToClientTemplate())
</script>

 

Thank you very much!

   

2 Answers, 1 is accepted

Sort by
0
Accepted
Boyan Dimitrov
Telerik team
answered on 07 Aug 2015, 12:05 PM

Hello Stephen,

I am afraid that this could not be achieved. The Kendo MVC view helper will be executed on the server, but the client expression will be executed on the client. 

The only way is to keep hiding the columns on the client side. 

Regards,
Boyan Dimitrov
Telerik
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
0
Stephen
Top achievements
Rank 1
answered on 12 Aug 2015, 04:28 PM
Thanks!
Tags
Grid
Asked by
Stephen
Top achievements
Rank 1
Answers by
Boyan Dimitrov
Telerik team
Stephen
Top achievements
Rank 1
Share this question
or