0
votes

I want to group my rows by year. I don't have a column with a int Year but I got a column of type Date.

In my column def I added the rowGroup:true to activate grouping.

Now how do I tell aggrid that i want grouping on the year property of my date ?

Is it based on the valueFormatter ?

function (data) { 
  if (data.value == undefined) return ""; 
  var val = (new Date(data.value)).getFullYear(); 
  return val;
}

Is it based on the comparator func ?

comparator: function (date1, date2) {
 if (date1 == undefined) return -1;
 if (date2 == undefined) return 1;
 var year1 = date1.getFullYear();
 var year2 = date2.getFullYear();
 if (year1 == year2)  return 0;
 return (year1 < year2) ?-1:1;
}

I had a breakpoint in comparator. it looks like it's never get called.

Is it in the cellFormatter ? The cellRenderer ?

Right now I got the group behaviour (checkbox to un/fold group of rows). But I got n groups called "2018", one for each date.

Bonus question : how can I display this column as a group and not shows as a normal column ? I want to group by year-only and display a "second" column with the full date dd/mm/yyyy.

1
sorry, but I didn't get what exactly you are trying to achieve, pls provide your code example and define questions more clearly. btw about date filter comparison, you could check this part of doc - un.spike
Sorry, I thought it was rather clear. I want row grouping. I got rows with a full date (day/month/year). I want to group all rows that have the same year. I want the grid to add "virtual" rows called 2016,2017,2018... and hide the actual rows. One click on 2018 should display the actual rows of 2018. A second click will hide the rows of 2018. Fold/Unfold/fold/unfold... - frenchone

1 Answers

0
votes

What you could do is create an additional column that based on the date field, is grouped but hidden as a column. Use a valueGetter to display the year:

function yearGetterFunction(params) {
  if (params.data.yourDateField== undefined) return ""; 
    var val = (new Date(params.data.yourDateField)).getFullYear(); 
    return val;
}

coldefs:[
    // your other columns, 
    {headerName: "Year", field: "yourDateField" valueGetter: yearGetterFunction, rowGroup:true, hide:true}
]