I'm using ag-grid 9.X with angularJs and when trying to set the comparator function for a date column, it doesn't get triggered.
{
headerName: 'Date',
field: 'lastDate',
width:100,
sortable: true,
comparator: dateComparator,
}
I also set enableSorting: true
. Is there any chance that the feature is not available in that version of ag-grid ?
Thanks !
So, since I was not able to get the comparator function to work, I used the following tips to sort date columns :
Making sure that the original data that feeds into the grid has Javascript Date objects for that column and not strings (so that ag-grid's sort algorithm (which uses the ">" operator) can compare these dates as dates and not strings) Example :
data.forEach(function(obj,i){
let dateStr = obj.date
let year = dateStr.substring(0, 4)
let month = dateStr.substring(5, 7)
let day = dateStr.substring(8, 10)
let time = dateStr.substring(11, 21)
let date = new Date(year+"-"+month+"-"+day+" "+time)
data[i].date = date
})
$scope.gridConfig.data = data
In fact, what I've come to realize through this issue is that ag-grid sorting algorithm doesn't act on the data rendered by cellRenderer nor the valueGetter. It actually uses the original data.