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

Group Header Template

4 Answers 1257 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Steve
Top achievements
Rank 1
Steve asked on 19 Jun 2019, 11:06 AM

I'm trying to add Group Headers to my grid, but can't get anything to display. Aggregate footers are fine, but headers just don't seem to work. Example grid...

@(Html.Kendo().Grid<PersonTimesheetSummary>()
                    .Name("grid")
                    .Columns(columns => {
                        columns.Bound(p => p.PersonCode);
                        columns.Bound(p => p.FullName);
                        columns.Bound(p => p.NoOfTimesheetDays).ClientGroupHeaderTemplate("#=sum#");
                    })
                    .DataSource(dataSource => dataSource
                        .Ajax()
                        .Aggregates(aggregates =>
                        {
                            aggregates.Add(p => p.NoOfTimesheetDays).Sum();
                        })
                        .Group(groups => { groups.Add(p => p.Company); groups.Add(p => p.Department); })
                        .Read(read => read.Action("GetPersonTimesheetSummary", "Person").Data("getGridParams")))
                )

I've tried this using the Html and tag helper formats with no success. I'm using version 2019.2.514.

4 Answers, 1 is accepted

Sort by
0
Marin Bratanov
Telerik team
answered on 24 Jun 2019, 05:31 AM
Hello Steve,

I am attaching here a small sample that shows how this can work so you can use it as a reference. The key difference is that I added grouping by the NoOfTimesheetDays field, so that it actually forms groups where you can see the ClientGroupHeaderTemplate.

If you want to see the sums in the current groups (by company and department), you should use the ClientGroupHeaderColumnTemplate. You can read more about the difference between them in the following article: https://docs.telerik.com/kendo-ui/controls/data-management/grid/Templates/group-templates. I am attaching a second version of the sample that showcases this as well.

It is perhaps also important to note that you must be using a version after R3 2018 so you can use the group header column template, and this includes the Kendo client assets that are usually in the _Layout file.


Regards,
Marin Bratanov
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Steve
Top achievements
Rank 1
answered on 24 Jun 2019, 09:48 AM

Hi Marin

I hadn't appreciated that there was a ClientGroupHeaderColumnTemplate, probably because I'm using tag helpers and it doesn't seem to exist as a 'column' tag attribute. "group-header-template" is there, but no "group-header-column-template". Am I looking in the wrong place?

Thanks

Steve

0
Accepted
Marin Bratanov
Telerik team
answered on 25 Jun 2019, 06:32 AM
Hello Steve,

Indeed, this is not available through the tag helper at the moment. You can track its status in the following issue I opened for adding it: https://github.com/telerik/kendo-ui-core/issues/5133.

You can achieve it with the following code in the meantime:

<kendo-grid name="grid2">
    <datasource type="DataSourceTagHelperType.Ajax">
        <transport>
            <read url="/Person/GetPersonTimesheetSummary" data="getGridParams" />
        </transport>
        <aggregates>
            <aggregate field="NoOfTimesheetDays" aggregate="sum" />
        </aggregates>
        <groups>
            <group field="Company">
                <aggregates>
                    <aggregate field="NoOfTimesheetDays" aggregate="sum" />
                </aggregates>
            </group>
            <group field="Department">
                <aggregates>
                    <aggregate field="NoOfTimesheetDays" aggregate="sum" />
                </aggregates>
            </group>
        </groups>
    </datasource>
    <groupable enabled="true" />
    <sortable enabled="true" />
    <filterable enabled="true" />
    <columns>
        <column field="PersonCode" />
        <column field="FullName" />
        <column field="NoOfTimesheetDays" />
    </columns>
</kendo-grid>
 
<script>
    $(document).ready(function () {
        var grid = $("#grid2").data("kendoGrid");
        var opts = grid.options;
        for (var i = 0; i < grid.options.columns.length; i++) {
            if (grid.options.columns[i].field == "NoOfTimesheetDays") {
                grid.options.columns[i].groupHeaderColumnTemplate = "#=sum#";
            }
        }
        grid.setOptions(opts);
    });
</script>


Regards,
Marin Bratanov
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Steve
Top achievements
Rank 1
answered on 25 Jun 2019, 07:22 AM
Thanks, Marin. This works as you've suggested.
Tags
Grid
Asked by
Steve
Top achievements
Rank 1
Answers by
Marin Bratanov
Telerik team
Steve
Top achievements
Rank 1
Share this question
or