If you decide to use a String for this process, the grid may not render correctly at first because it will attempt to format with the String.
Therefore, shortly after setting it up, you will need to update the columnDefs
.
You will need to locate the function, update the columnDef
to have the valueFormatter point to the function, and then use setColumnDefs
and refreshRows
to rebuild the DOM with the function assigned.
For example:
// obtain the current column definitions
var columnDefs = gridOptions.api.getColumnDefs();
// iterate through each one
columnDefs.forEach(colDef =>{
// if it has a valueFormatter
if(colDef.valueFormatter){
// and it is a string
if(typeof colDef.valueFormatter == "string"){
// if the function is found
if(window[colDef.valueFormatter]
&& typeof window[colDef.valueFormatter]=="function"){
// assign the function as the valueFormatter
colDef.valueFormatter = window[colDef.valueFormatter];
}
}
}
});
// reconfigure the grid with the updated definitions
gridOptions.api.setColumnDefs(columnDefs);
// trigger a redraw to apply the function
gridOptions.api.redrawRows();