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

Can we customize the group header in React Grid

1 Answer 715 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Zhichao
Top achievements
Rank 1
Zhichao asked on 06 Sep 2018, 11:31 AM

Two questions about the aggregate feature: https://www.telerik.com/kendo-react-ui/components/grid/grouping/grouping/:

1.      Do we have some kind of groupHeaderTemplate function to customize the template of group header? Like what JQuery has:

https://docs.telerik.com/kendo-ui/api/javascript/ui/grid/configuration/columns.groupheadertemplate

or

2. For the example in

https://www.telerik.com/kendo-react-ui/components/grid/grouping/grouping/

Can we aggregate the summary information on the header, instead of footer?

1 Answer, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 07 Sep 2018, 06:38 AM
Hello, Zhichao,

Currently, if the header has to be modified the changes has to be applied on a data level.

There is a discussion on this and at the end, there is a code demonstrating how to recursively access the groupHeaders in order to modify them:

https://github.com/telerik/kendo-react/issues/53

Also, the aggregates can be shown in the header using the headerCell renderer:

https://www.telerik.com/kendo-react-ui/components/grid/api/GridColumnProps/#toc-headercell

The code may look like this:

class CustomHeaderCell extends React.Component {
    render() {
      const aggregates =  aggregateBy(products, [{field:"UnitPrice", aggregate: "average"}, {field:"UnitsInStock", aggregate: "sum"}])
      const aggregate = this.props.field === "UnitPrice" ? aggregates.UnitPrice.average : aggregates.UnitsInStock.sum
        return (
            <a className="k-link" onClick={this.props.onClick}>
              <span>{this.props.title}</span>
              <br/>
              <strong>{this.props.field === "UnitPrice" ? "Average Price" : "Total Units" }: </strong>
              <span>{this.props.field === "UnitPrice" ? formatNumber(aggregate, "c"): aggregate } </span>
              {this.props.children}
            </a>
        );
    }
}

I hope this is helpful.

Regards,
Stefan
Progress 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
Tags
General Discussions
Asked by
Zhichao
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Share this question
or