Here's the material table setup I'm working with:
<table mat-table [dataSource]="dataSource" >
... Rows ...
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
<tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
</table>
<mat-paginator #MatPaginator [pageSizeOptions]="[4]" showFirstLastButtons></mat-paginator>
I want to hide the table when the variable info
is false.
- Strategy 1:
<table *ngIf="info" mat-table [dataSource]="dataSource" >
This approach works, but pagination malfunctions when all rows are displayed on one page.
- Strategy 2:
<table [hidden]="!info" mat-table [dataSource]="dataSource" >
Although this makes pagination work, the table still appears empty when info
is false.
- Strategy 3:
I attempted wrapping the entire table in a div
and using *ngIf
, but encountered the same issue as Strategy 1.
Even trying [hidden]
on the div
didn't solve the problem.
- UPDATE: Strategy 4:
By directly applying the CSS style="display:none"
to the enclosing div
, I faced the same dilemma as in Strategy 3 - the table shows up even without data.
Any suggestions on how to properly hide the table when
info
is false while ensuring functional pagination?
Appreciate any insights!