If you choose the option to use the controls (here FormGroups) of the FormArray as the data for the MatTableDataSource you can use this snippet to get the sorting and filtering working.
<div [formGroup]="tableFormGroup">
<table mat-table matSort matSortDirection="desc" [dataSource]="dataSource" [formArrayName]="formArrayName">
<!-- Price Column -->
<ng-container matColumnDef="price">
<th mat-header-cell *matHeaderCellDef mat-sort-header>Price</th>
<td mat-cell *matCellDef="let row; let index = dataIndex" [formGroupName]="getArrayIndex(row)">
<mat-form-field class="mat-input-table" [appearance]="'fill'" [subscriptSizing]="'dynamic'">
<input matInput [formControlName]="'price'">
</mat-form-field>
</td>
</ng-container>
<!-- [...] -->
//component.ts
getArrayIndex(row: FormGroup<TableItemForm>): number {
return this.dataSource.filteredData.findIndex((value: FormGroup<TableItemForm>): boolean =>
row.controls.id.value === value.controls.id.value)
}
Ensure that the "id" control values in the formGroups are unique across the entire formArray. This approach may not be the most efficient since getArrayIndex is called each time you hover over a row element, but it functions as expected. For a more detailed description of the task, please refer this article here.