Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AG-Grid dynamic column header text

This seems like it'd be simple but it's proving otherwise. For some reason headerName is converted to a string and so it can't be a function.

I've also tried various renderer and headerComponent functions but like I said, I just want to return a dynamic string, not override everything and have to re-implement it (such as with the case of a custom header component).

// I'm trying everything at this point, nothing renders out..
getHeaderCellTemplate: () => 'test 2',
headerCellTemplate: () => {
  // What I actually want to achieve:
  const currency = appModel.selectedCertificate().currency();
  return currency ? `Total Value (${currency})` : 'Total Value';
},
headerCellRenderer: HeaderCellRenderer,
headerComponent: HeaderCellRenderer,
cellRenderer: () => 'test 7',
headerRenderer: () => 'test 9',

I know I could wrap the column def in a function, but this would be very inefficient as the column def would be re-created every render.

like image 739
Dominic Avatar asked Jan 29 '23 19:01

Dominic


1 Answers

I expect this will work for you:

headerValueGetter: (params) => {
  const currency = appModel.selectedCertificate().currency();
  return currency ? `Total Value (${currency})` : 'Total Value';
}
like image 129
Jarod Moser Avatar answered Jan 31 '23 07:01

Jarod Moser