How do I change the cellRenderer function into a reusable variable? I have tried using a constructor, and declaring a variable, seems simple, but any help would be appreciated.
import {Component} from 'angular2/core';
@Component({
selector: 'app',
template: '<ag-grid-ng2 class="ag-fresh" style="height: 300px" [columnDefs]="columnDefs" [rowData] = "rowData"></ag-grid-ng2>',
directives: [(<any>window).ag.grid.AgGridNg2]
})
export class SampleAppComponent {
columnDefs = [
{ headerName: "Make", field: "make" },
{ headerName: "Model", field: "model" },
{
headerName: "Price",
field: "price",
cellClass: 'rightJustify',
cellRenderer: function (params: any) {
return '$' + params.value.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","); //thanks http://stackoverflow.com/users/28324/elias-zamaria
}
}
];
}
What am I doing wrong here?
export class SampleAppComponent {
constructor() {
this.convertToMoney = function (params: any) {
return '$' + params.value.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","); //thanks http://stackoverflow.com/users/28324/elias-zamaria
};
columnDefs = [
{ headerName: "Line Type", field: "line" },
{ headerName: "Expense Type", field: "expense" },
{
headerName: "Totals",
field: "totals",
cellClass: 'rightJustify',
cellRenderer: convertToMoney()
}
];