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

Grid grouped headers with aggregated values

1 Answer 126 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Andreas
Top achievements
Rank 1
Andreas asked on 24 Oct 2018, 01:07 PM

     I wonder if and how I would be able to get the aggregated value for a group in the grid to be displayed after the group name?

Say I group my products on Product category and I aggregate the Quantity in stock - how would I get the group names in a collapsed state say "Category 1, Quantity in stock: 450"?

1 Answer, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 25 Oct 2018, 09:53 AM
Hello, Andreas,

The desired result can be achieved using the cellRender. It will require checking if this is a group header cell and based on that to modify its content:

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

cellRender(tdElement, cellProps) {
 
  if (cellProps.rowType === 'groupHeader' && cellProps.field === "value") {
    tdElement = (<td colSpan={6}>
      <p className="k-reset">
        <a href="#"
          tabIndex="-1"
          className={cellProps.expanded ? 'k-i-collapse k-icon' : 'k-i-expand k-icon'}
          onClick={(e) => {
            e.preventDefault();
            if (cellProps.onChange) {
              cellProps.onChange({
                dataItem: cellProps.dataItem,
                syntheticEvent: e,
                field: undefined,
                value: !cellProps.expanded
              });
            }
          }}></a>
        {cellProps.dataItem.value}: 
        Total Units is stock: {cellProps.dataItem.aggregates.UnitsInStock.sum}
      </p>
    </td>
    );
  }
  return tdElement;
}

https://stackblitz.com/edit/react-8qdqqi?file=app/main.js

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
Andreas
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Share this question
or