I’m dynamically building my ag-Grid columns from data received via a web service (here is a snippet of my code where I am building up my column definitions; see plunker for entire example):
for (let i = 0; i < cr.attributes.length; i++) {
let displayAlignment = '';
switch (cr.attributes[i].dispAlign) {
case 'C':
displayAlignment = 'center';
break;
case 'L':
displayAlignment = 'left';
break;
case 'R':
displayAlignment = 'right';
break;
default:
throw new Error('this will never happen, dispAlign for database must have value');
}
const displayMask = cr.attributes[i].dispMask;
// console.log('displayMask: ', displayMask);
const dataType = cr.attributes[i].dataType;
// console.log('dataType: ', dataType);
// console.log('cr attributes: ' , cr.attributes );
childColDefsString = childColDefsString +
'{"field": "' + cr.attributes[i].label + '"' +
', "cellStyle": {"textAlign": "' + displayAlignment + '"}' +
', "valueFormatter": "this.customValueFormatter(datatype, displayMask)"' +
', "width": 175, ' + '"hide": ' + cr.attributes[i].hide + '},';
}
As I build up my columns I add a cellStyle for column justification based on the column type received from the web service (which is working as expected). I’m also trying to add a valueFormatter that attempts to call a custom formatter. Unfortunately, as the rowData is applied (by clicking the "Apply Row Data" button) to the grid I'm encountering the following ag-Grid thrown exception (seen via Chrome -> Inspect -> Console):
Processing of the expression failed ag-grid.js:10595
Expression = customValueFormatter(datatype, displayMask) ag-grid.js:10596
Exception = ReferenceError: customValueFormatter is not defined
Here is a url to a Plunker example I'v created: https://plnkr.co/edit/LcA5dRU9g8huLUWv3syZ?p=preview
I've tried several iterations of an ag-Grid example, https://www.ag-grid.com/javascript-grid-value-setters/ , to no avail.