Example Data:
[{ 'ID': objID(abc123),
'Department': 'IT',
'Employees': [ { 'ID': 3, 'StartDate': '24-12-2022T08:30', 'active': true },
{ 'ID': 2, 'StartDate': '14-11-2021T08:30', 'active': true },
{ 'ID': 1, 'StartDate': '22-11-2020T08:30', 'active': false }]
},
{ 'ID': objID(def456),
'Department': 'HR',
'Employees': [ { 'ID': 33, 'StartDate': '24-12-2022T08:30', 'active': false},
{ 'ID': 22, 'StartDate': '14-11-2021T08:30', 'active': true },
{ 'ID': 11, 'StartDate': '22-11-2020T08:30', 'active': false }]
},
{ 'ID': objID(ghi789),'Department' : 'AC', 'Employees': []}... more than 1000 ]
Table HTML Code:
<tbody>
<ng-container *ngFor="let dept of Department">
<tr *ngFor="let emp of dept.Employees" class="card-text">
<td> {{dept.Department}} </td>
<td> {{emp.ID}} </td>
<td> {{emp.StartDate}} </td>
<td> {{emp.active}} </td>
</tr>
</ng-container>
</tbody>
Current Display:
Department ID StartDate active
IT 3 24-12-2022T08:30 true
IT 2 14-11-2021T08:30 true
IT 1 22-11-2020T08:30 false
HR 33 24-12-2022T08:30 false
HR 22 14-11-2021T08:30 true
HR 11 22-11-2020T08:30 false
Expected Output:
Department ID StartDate active
IT 3 24-12-2022T08:30 true
IT 2 14-11-2021T08:30 true
HR 22 14-11-2021T08:30 true
HR 33 24-12-2022T08:30 false
IT 1 22-11-2020T08:30 false
HR 11 22-11-2020T08:30 false
Attempted Solution:
this.data.forEach(entry => {
console.log('checking:', entry)
entry.Employees.sort((a:any, b:any) => { return a.StartDate - b.StartDate })})
In this case, I am aiming to sort the data first by activity status and then by dates from recent to oldest.
I am open to exploring alternative methods to achieve the desired output.