AG-Grid dynamic column header text

左心房为你撑大大i 提交于 2019-12-23 23:51:59

问题


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.


回答1:


I expect this will work for you:

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


来源:https://stackoverflow.com/questions/48407124/ag-grid-dynamic-column-header-text

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!