【发布时间】:2021-02-21 18:52:11
【问题描述】:
我试图在我的网页上显示一些带有角度材料表的数据,但视图看起来不太好,我该怎么办? 我想让可调整大小的列和数据放在正确的位置,而不是那样混乱
这是显示全部数据的 HTML 代码
<mat-card>customer card</mat-card>
<div>
<mat-table [dataSource]="dataSource" class="mat-elevation-z8" class="table">
<!-- Position Column -->
<ng-container matColumnDef="firstName">
<mat-header-cell *matHeaderCellDef> firstName </mat-header-cell>
<mat-cell *matCellDef="let element"> {{element.firstName}} </mat-cell>
</ng-container>
<ng-container matColumnDef="lastName">
<mat-header-cell *matHeaderCellDef> lastName </mat-header-cell>
<mat-cell *matCellDef="let element"> {{element.lastName}} </mat-cell>
</ng-container>
<ng-container matColumnDef="email">
<mat-header-cell *matHeaderCellDef> email </mat-header-cell>
<mat-cell *matCellDef="let element"> {{element.email}} </mat-cell>
</ng-container>
<ng-container matColumnDef="phoneNumber">
<mat-header-cell *matHeaderCellDef> phoneNumber </mat-header-cell>
<mat-cell *matCellDef="let element"> {{element.phoneNumber}} </mat-cell>
</ng-container>
<ng-container matColumnDef="orderStatus">
<mat-header-cell *matHeaderCellDef> orderStatus </mat-header-cell>
<mat-cell *matCellDef="let element"> {{element.orderStatus}} </mat-cell>
</ng-container>
<ng-container matColumnDef="deliveryDate">
<mat-header-cell *matHeaderCellDef> deliveryDate </mat-header-cell>
<mat-cell *matCellDef="let element"> {{element.deliveryDate}} </mat-cell>
</ng-container>
<ng-container matColumnDef="storeName">
<mat-header-cell *matHeaderCellDef> storeName </mat-header-cell>
<mat-cell *matCellDef="let element"> {{element.storeName}} </mat-cell>
</ng-container>
<ng-container matColumnDef="storeAddress">
<mat-header-cell *matHeaderCellDef> storeAddress </mat-header-cell>
<mat-cell *matCellDef="let element"> {{element.storeAddress}} </mat-cell>
</ng-container>
<ng-container matColumnDef="storePhone">
<mat-header-cell *matHeaderCellDef> storePhone </mat-header-cell>
<mat-cell *matCellDef="let element"> {{element.storePhone}} </mat-cell>
</ng-container>
<ng-container matColumnDef="price">
<th mat-header-cell *matHeaderCellDef >price</th>
<td mat-cell *matCellDef="let element">
<mat-form-field>
<input [(ngModel)]="element.price" matInput placeholder="Price" name="price">
</mat-form-field>
</td>
</ng-container>
<ng-container matColumnDef="save">
<th mat-header-cell *matHeaderCellDef></th>
<td mat-cell *matCellDef="let element">
<button (click)="post(element.price)" mat-button>save</button></td>
</ng-container>
<mat-header-row *matHeaderRowDef="displayedColumns"></mat-header-row>
<mat-row *matRowDef="let row; columns: displayedColumns;"></mat-row>
</mat-table>
<!-- <button (click)="post(price)" mat-button>save</button> -->
</div>
这是我使用的 CSS
.mat-table {
width: 100%;
overflow: auto;
}
mat-cell,
mat-footer-cell,
mat-header-cell {
width: 200px;
flex: none;
justify-content: center;
}
.mat-table mat-cell:first-child {
padding-left: 0px;
border-left: 1px solid;
}
.mat-table mat-cell:last-child {
padding-right: 0px;
}
.mat-table mat-header-cell:first-child {
padding-left: 0px;
border-left: 1px solid;
}
.mat-table mat-header-cell:last-child {
padding-right: 0px;
}
.mat-table mat-header-cell {
border-top: 1px solid;
border-right: 1px solid;
border-bottom: 1px solid;
cursor: col-resize;
}
.mat-table mat-cell {
border-right: 1px solid;
border-bottom: 1px solid;
}
【问题讨论】:
-
欢迎来到 Stack Overflow。请在您的问题中添加一个最小且可重现的示例,以便在代码中有一个起点。另见stackoverflow.com/help/minimal-reproducible-example
标签: angular-material