Сначала создайте массив, сгруппированный по shortname
и вычислите общее количество, затем добавьте атрибут rowspan
на основе условия.
// HTML код
<table class="table table-bordered">
<thead>
<tr>
<th>Faculty</th>
<th>Program</th>
<th>Total Applicant</th>
<th>Faculty Total</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let admit of admitList; let i = index">
<td>{{admit.shortName}}</td>
<td>{{admit.programName}}</td>
<td>{{admit.totalApplicant}}</td>
<td *ngIf="i==0 || admit.shortName !== admitList[i-1].shortName" [attr.rowspan] = "(groupbyShortName[admit.shortName].count) ? groupbyShortName[admit.shortName].count : 0">{{groupbyShortName[admit.shortName].sum}}</td>
</tr>
</tbody>
</table>
// Код компонента
import {Component, OnInit} from '@angular/core';
@Component({
selector: 'ngbd-datepicker-popup',
templateUrl: './datepicker-popup.html'
})
export class NgbdDatepickerPopup implements OnInit {
groupbyShortName = {};
admitList = [
{
shortName: 'FSIT',
programName: 'BSc in CSE',
totalApplicant: 10
},
{
shortName: 'FSIT',
programName: 'BSc in SWE',
totalApplicant: 5
},
{
shortName: 'FSIT',
programName: 'BSc in EEE',
totalApplicant: 15
},
{
shortName: 'FAHS',
programName: 'BSc in LLB',
totalApplicant: 10
},
{
shortName: 'FAHS',
programName: 'BSc in English',
totalApplicant: 5
},
{
shortName: 'FAHS',
programName: 'BSc in Pharmacy',
totalApplicant: 8
}
];
constructor() {
this.groupbyShortName = this.admitList.reduce((accu, {shortName, totalApplicant, programName}) => {
if(!accu[shortName])
accu[shortName] = {count: 0, sum: 0, shortName, totalApplicant, programName};
accu[shortName].count += 1;
accu[shortName].sum += totalApplicant;
return accu;
}, {});
}
ngOnInit() { }
}