I'm struggling to change the date format of two dates displayed in one cell using ag-grid. I have tried creating a new function called dateFormatterr with two parameters, but it doesn't seem to work. Below is a snippet of my code and a screenshot of the ag-grid in question:
import { Component, OnInit } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Grid, GridApi } from 'ag-grid-community';
import { AgGridAngular } from 'ag-grid-angular';
import { DealsService } from './services/deals.service';
import * as moment from 'moment';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
export class AppComponent implements OnInit {
title = 'app';
gridOptions = {
rowHeight: 70
}
columnDefs = [{
headerName: "Block \n Deal",
cellRenderer: function(params) {
return params.data.BLOCKID + '<br/>' + params.data.DEALID
},
width: 150,
resizable: true,
filter: true
},
{
headerName: 'Class \n Type',
cellRenderer: function(params) {
return params.data.DEALCLASS + '<br/>' + params.data.DEALTYPE
},
width: 150,
resizable: true,
filter: true
},
{
headerName: 'Trade \n Start',
cellRenderer: function(params) {
return params.data.TRADEDATE + '<br/>' + params.data.STARTDATE
},
valueFormatter: this.dateFormatterr('TRADEDATE', 'STARTDATE'),
width: 150,
resizable: true,
filter: true,
},
{
headerName: 'Folder \n Cpty',
cellRenderer: function(params) {
return params.data.FOLDERSHORTNAME + '<br/>' + params.data.CPTYSHORTNAME
},
width: 150,
resizable: true,
filter: true
},
{
headerName: 'ShortName \n Name',
cellRenderer: function(params) {
return params.data.INSTRSHORTNAME + '<br/>' + params.data.INSTRNAME
},
width: 150,
resizable: true,
filter: true,
},
{
headerName: 'Quantity \n Settl.Amt',
cellRenderer: function(params) {
return params.data.QUANTITY + '<br/>' + params.data.SETTLEAMT
},
width: 150,
resizable: true,
filter: true
},
{
headerName: 'Rate \n Fees',
cellRenderer: function(params) {
return params.data.FLOATINGRATESSHORTNAME + '<br/>' + params.data.RENTSPREADFIXEDRATE
},
width: 150,
resizable: true,
filter: true
},
{
headerName: 'Category \n Status',
cellRenderer: function(params) {
return params.data.DEALCAT + '<br/>' + params.data.WORKFLOWSTATE
},
width: 150,
resizable: true,
filter: true
},
{
headerName: 'End',
field: 'ENDDATE',
valueFormatter: this.dateFormatter,
width: 140,
resizable: true,
filter: true
},
];
rowData: any;
constructor(private service: DealsService) {}
dateFormatter(params) {
return moment(params.value).format('DD/MM/YYYY');
}
dateFormatterr(params1, params2) {
return moment(params1.value + params2.value).format('DD/MM/YYYY');
}
ngOnInit() {
this.service.getDealsList().subscribe(data => {
this.rowData = data;
});
}
}
Your assistance with this issue is greatly appreciated. Thank you.