How can I show total in header?
For example, I want to show sum of age as Age(x)
In ag-grid add onRowDataChanged
event and create function.
<AgGridReact onRowDataChanged={onRowDataChanged}></AgGridReact>
Using ag-grid column api to get column object and change its header name. After that, refresh the header component
const onRowDataChanged = (params) => {
var ageColumn = gridRef.current.columnApi.getColumn("age")
var rowCount = gridRef.current.api.getDisplayedRowCount()
ageColumn.colDef.headerName = `Age ${rowCount}`;
gridRef.current.api.refreshHeader();
}
If you are using AdapTable with AG grid then you dont need any code.
Just set showGroupingTotalsAsHeader
to true in General Options and AdapTable will do it for you:
https://docs.adaptabletools.com/guide/reference-options-general#showgroupingtotalsasheader