I have two arrays which have mutual ID, so I am able to connect them together but I need help with filtering.
So I have a list of first array and check box in front of it. If I select one check box, I am performing filtering and I am displaying another item from second array inside the table (by checking up the mutual ID).
I need help because if I perform multiple selection, I expect to have multiple results, and not just one. This is the image how it looks like and the code I am using for filtering.
So if I select check box for Item 1 and Item 2 I expect to have 3 results (ids 10, 20(x2)) from apps array in the lower table. Of course if I deselect check box, they should be removed from the lower table. Because I am using only .filter method, I am able to get only one result (from last selected checkbox).
let items = [
{id:1, name:'Item 1', appId:10},
{id:2, name:'Item 2', appId:20},
{id:3, name:'Item 3', appId:20},
{id:4, name:'Item 4', appId:30}
]
let apps = [
{id:10, address:'Some street 1', city:'City 1'},
{id:20, address:'Some street 2', city:'City 2'},
{id:20, address:'Some street 2', city:'City 2'},
{id:30, address:'Some street 3', city:'City 3'}
]
this.dataSource = this.items.filter(x => x.appId == apps.id)
Thanks
UPDATE
I have managed to do it by Rohit's answer, but I have a problem now because when I select check box in first array, all previously selected check boxes in second array are being removed, so the question is how to keep them?
I have added new images, before and after, so after selecting check box Item 1, I expect check boxes for Some street 9 and Some street 10 to remain selected.
My html.
<table mat-table [dataSource]="dataSourceObjects" class="mat-elevation-z8">
<ng-container matColumnDef="objectChBox">
<th mat-header-cell *matHeaderCellDef></th>
<td mat-cell *matCellDef="let element">
<mat-checkbox
class=""
[checked]="element.chbxActive"
(change)="checkSingleObject($event, element)"
>
</mat-checkbox>
</td>
</ng-container>
<ng-container matColumnDef="address">
<th mat-header-cell *matHeaderCellDef>Address</th>
<td mat-cell *matCellDef="let element">{{element.address}}</td>
</ng-container>
<ng-container matColumnDef="city">
<th mat-header-cell *matHeaderCellDef>City</th>
<td mat-cell *matCellDef="let element">{{element.city}}</td>
</ng-container>
<tr mat-header-row *matHeaderRowDef="displayedColumnsObjects"></tr>
<tr mat-row *matRowDef="let row; columns: displayedColumnsObjects;"></tr>
</table>



app.id? What doesitemsand "the second array" look like and how are they connected?