Reputation: 447
I wanted to update the individual count (applicable, not applicable) once the filters are applied. It's currently only updating the total count.
Please assist.
Live: https://angular-ivy-dubf37.stackblitz.io/
getCounts() {
this.impactCount = { applicable: 0, notApplicable: 0, fyi: 0 };
this.allUser.forEach(row => {
// impact counts
if (row.impact === "Applicable") {
this.impactCount.applicable++;
} else if (row.impact === "Not Applicable") {
this.impactCount.notApplicable++;
} else if (row.impact === "FYI") {
this.impactCount.fyi++;
}
});
}
Upvotes: 0
Views: 42
Reputation: 2334
You problem is when you change filter pipe knows new data but you getcount function doesn't know data has changed
As a simple solution (may be a dirty solution.I am also open to suggestions: D) First of all, I changed your getCount method a bit.
getCounts (user ?: any) {
this.impactCount = {applicable: 0, notApplicable: 0, fyi: 0};
let data = user? user: this.allUser;
data.forEach (row => {
if (row.impact === "Applicable") (
this.impactCount.applicable ++;
} else if (row.impact === "Not Applicable") {
this.impactCount.notApplicable ++;
} else if (row.impact === "FYI") {
this.impactCount.fyi ++;
}
});
}
then send pipe return values with your getCount
function as below
<ng-container *ngIf="allUser | tableFilter: form.value as filteredUsers">
<div class="text-right toal-records">
Total: {{filteredUsers.length}}
{{getCounts(filteredUsers)}}
</div>
<div style="padding-left: 20px">
Applicable: {{impactCount.applicable}} Not Applicable:
{{impactCount.notApplicable}} FYI: {{impactCount.fyi}}
</div>
also i updated your demo project
Upvotes: 1