简体   繁体   English

AG-Grid动态列标题文本

[英]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. 由于某种原因, headerName被转换为字符串,因此它不能成为函数。

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). 我还尝试了各种rendererheaderComponent函数,但是就像我说的那样,我只想返回一个动态字符串,而不是覆盖所有内容并必须重新实现它(例如,使用自定义标头组件的情况)。

// 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. 我知道我可以将column def包装在一个函数中,但这会非常低效,因为将在每次渲染时重新创建column def。

I expect this will work for you: 我希望这对您有用:

headerValueGetter: (params) => {
  const currency = appModel.selectedCertificate().currency();
  return currency ? `Total Value (${currency})` : 'Total Value';
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM