So I have the following dataset that I would like to group/aggregate by Year, Month using the dateObject property.
Dataset
$scope.dataSet = [
{
_id : 58b57e442bf752389a940fea,
time : 01:39 PM,
status : Submitted,
date : 2017-02-28T13:39:34.955Z,
dateObject : {
dayOfTheMonth : 28,
dayOfTheWeek : Tuesday,
month : February,
year : 2017
}
},
{
_id : 58b57e442bf9820389a940fea,
time : 05:18 PM,
status : Submitted,
date : 2014-02-28T13:39:34.955Z,
dateObject : {
dayOfTheMonth : 28,
dayOfTheWeek : Tuesday,
month : February,
year : 2014
}
},
{
_id : 58b57e442bf9820389a940fea,
time : 05:55 AM,
status : Processing,
date : 2016-03-18T13:39:34.955Z,
dateObject : {
dayOfTheMonth : 18,
dayOfTheWeek : Friday,
month : March,
year : 2016
}
}
]
Here is how I would like to structure the data after aggregating it:
[
{
'2017' : [
'March' : [
{
_id : 58b57e442bf752389a940fea,
time : 01:39 PM,
status : Submitted,
date : 2017-02-28T13:39:34.955Z,
dateObject : {
dayOfTheMonth : 28,
dayOfTheWeek : Tuesday,
month : February,
year : 2017
}
}
]
]
},
{
'2016' : [
'February' : [
{
_id : 58b57e442bf9820389a940fea,
time : 05:55 AM,
status : Processing,
date : 2016-03-18T13:39:34.955Z,
dateObject : {
dayOfTheMonth : 18,
dayOfTheWeek : Friday,
month : March,
year : 2016
}
}
]
]
},
{
'2014' : [
'February' : [
{
_id : 58b57e442bf9820389a940fea,
time : 05:18 PM,
status : Submitted,
date : 2014-02-28T13:39:34.955Z,
dateObject : {
dayOfTheMonth : 28,
dayOfTheWeek : Tuesday,
month : February,
year : 2014
}
}
]
]
}
]
$scope.dataByYear = $filter('groupBy')($scope.dataSet, 'dateObject.year')
$scope.dataByMonth = $filter('groupBy')($scope.dataSet, 'dateObject.month')
When using $filter from AngularJS (As seen above), I am able to group the dataset by year or by month. My problem is that I would like to group the dataset by Year and Month. How can I achieve that?