Angular material 角度材质表调整列大小
我试图在我的网页上用一个有角度的材质表显示一些数据,但是视图看起来不太好,我该怎么办? 我想让可调整大小的列和数据位于正确的位置,而不是像那样凌乱 这是我的HTML代码,它显示了整个数据Angular material 角度材质表调整列大小,angular-material,Angular Material,我试图在我的网页上用一个有角度的材质表显示一些数据,但是视图看起来不太好,我该怎么办? 我想让可调整大小的列和数据位于正确的位置,而不是像那样凌乱 这是我的HTML代码,它显示了整个数据 <mat-card>customer card</mat-card> <div> <mat-table [dataSource]="dataSource" class="mat-elevation-z8" class="table"> <!--
<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>
这就是结果。而且输出看起来一点也不好。我该怎么办?
您使用的是Angular Material V5标准HTML代码。更改HTML(我在下面提供)并删除CSS 如果您使用的是angular版本6或更高版本,那么请使用下面的HTML 参考-
名字
{{element.firstName}
姓氏
{{element.lastName}
电子邮件
{{element.email}
电话号码
{{element.phoneNumber}
订单状态
{{element.orderStatus}
交货日期
{{element.deliveryDate}
店名
{{element.storeName}
店址
{{element.storeAddress}
存储电话
{{element.storePhone}
价格
拯救
欢迎来到堆栈溢出。请在您的问题中添加一个最小且可重复的示例,以便在代码中有一个起点。另见
.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;
}