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

Hide column based on values of footer

2 Answers 189 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Stephen
Top achievements
Rank 1
Stephen asked on 13 Oct 2015, 04:15 PM

I was wondering how to hide/show columns based on  the values of aggregate values in footer. For example:

  @(Html.Kendo().Grid<Payroll.Models.PayrollAuthorizationByDepartmentModel>()
.Name("Grid")

.Columns(columns =>
{
columns.Bound(dataSource => dataSource.EmployeeId).Title("Emp. No");
columns.Bound(dataSource => dataSource.EmployeeNameForDisplay).Title("Emp. Name");
columns.Bound(e => e.RegHours).Title("Reg.")
.ClientFooterTemplate("<div style='text-align: right'> \\#= kendo.toString(sum, '0.00')\\# </div>")
.ClientTemplate("\\#= kendo.toString(RegHours, '0.00')\\#");
columns.Bound(e => e.OTHours).Title("OverTime 1.5")
.ClientFooterTemplate("<div style='text-align: right'> \\#= kendo.toString(sum, '0.00')\\# </div>")
.ClientTemplate("\\#= (OTHours==0)? '':kendo.toString(OTHours, '0.00')\\#");                        
                        })
.DataSource(dataSource => dataSource
.Ajax()
.Aggregates(aggregates =>
{
aggregates.Add(e => e.RegHours).Sum();
aggregates.Add(e => e.OTHours).Sum();                                                              
                                                          })
.Read(read => read.Action("AuthorizationByEmployee_Read", "Authorize", new { locationId = @ViewBag.LocationId, departmentId = "#=DepartmentId#", startDate = @ViewBag.StartDate, endDate = @ViewBag.EndDate }))
.ServerOperation(false)
.Sort(sort => sort.Add("EmployeeFirstName").Ascending())
)
.Sortable()
.Events(events => events.DataBound("onDataBoundOfChildGrid"))
.ToClientTemplate()
)

 

How to hide the column if the sum is 0?

 

Thanks!

2 Answers, 1 is accepted

Sort by
0
Kostadin
Telerik team
answered on 15 Oct 2015, 08:09 AM
Hi Stephen,

You can hide the column by using hideColumn method and pass the column name as an argument. A possible solution to access the aggregate is to get it from the  dataSource. Please check out the following code snippet.
<script type="text/javascript">
 
    function onDataBound(arg) {
        var aggregates = arg.sender.dataSource.aggregates();
        if (aggregates.UnitsInStock.min == 0) {
            arg.sender.hideColumn("UnitsInStock")
        }
    }
 
</script>


Regards,
Kostadin
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 15 Oct 2015, 01:50 PM
Thank you. It works perfectly.
Tags
Grid
Asked by
Stephen
Top achievements
Rank 1
Answers by
Kostadin
Telerik team
Stephen
Top achievements
Rank 1
Share this question
or