Issue
I have problem with iterations through dataSource, where I have data for mat-table
<div *ngFor="let element of arrayMain" id = "{{element}}" class="my_item">
<div><span class="skuska"><span class="mat-subheading-2">{{element}}</span></span></div>
<mat-table #table [dataSource]="dataSource[1]" matSort>
<ng-container matColumnDef="{{column.id}}" *ngFor="let column of columnNames">
<mat-header-cell *matHeaderCellDef mat-sort-header > {{column.value}} </mat-header-cell>
<mat-cell *matCellDef="let element" [style.background]="element[column.id].color"> <div class="mat-cell-inner">{{element[column.id].name}}</div></mat-cell>
</ng-container>
M:<mat-header-row *matHeaderRowDef="displayedColumns"></mat-header-row>
<mat-row *matRowDef="let row; columns: displayedColumns;"></mat-row>
</mat-table>
</div>
The row with this data contain the problem
<mat-table #table [dataSource]="dataSource[1]" matSort>
I can only change the data when i change the number inside the array:
dataSource[0],dataSource[1]....,dataSource[n]
I try to use *ngFor cause
<mat-table *ngFor = "let calendars of dataSource" #table [dataSource]="{{calendars}}" matSort>
but it displays an error:
ng: Parser Error: Got interpolation ({{}}) where expression was expected at column 0 in [{{calendars}}] in @101:73
I fill the dataSource in function
for(identificator = 0; identificator < n; identificator++)
createData(identificator)
createData(identificator) {
some code...
.
.
.
this.dataSource[identificator] = new MatTableDataSource(testData);
this.dataSource[identificator].sort = this.sort;
}
How can I fix it? Any ideas? Thank you !
Solution
Try using index with ngFor to track your iterations. I hope its helpful.
<div *ngFor="let element of arrayMain, let myIndex=index" id="{{element}}" class="my_item">
<div>
<span class="skuska">
<span class="mat-subheading-2">{{element}}</span>
</span>
</div>
<mat-table #table [dataSource]="dataSource[myIndex]" matSort>
<ng-container matColumnDef="{{column.id}}" *ngFor="let column of columnNames">
<mat-header-cell *matHeaderCellDef mat-sort-header>
{{column.value}}
</mat-header-cell>
<!-- your same code -->
</ng-container>
</mat-table>
</div>
Answered By - Abhishek Kumar
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.