有没有一种方法可以设置响应表中的列具有成比例的宽度,我的意思是描述列将比日期列更宽。或者,有没有一种方法可以让表格根据所显示的内容进行自我设置?我考虑过在每一列上设置百分比宽度,但不确定这是否是最好的方法。
谢谢。
发布于 2019-09-26 02:32:47
是的,你可以做到的!这里有一个样例项目https://stackblitz.com/edit/angular-primeng-width?file=src/app/app.component.ts
在组件文件add width in column definition中:
this.columns = [
{ field: 'vin', header: 'Vin', width: '10%' },
{ field: 'year', header: 'Year', width: '20%' },
{ field: 'brand', header: 'Brand', width: '15%' },
{ field: 'color', header: 'Color', width: '5%' }
];在模板文件中使用宽度“{‘ngStyle=’:col.width}
<ng-template pTemplate="header" let-columns>
<tr>
<th *ngFor="let col of columns" [ngStyle]="{'width': col.width}">
{{col.header}}
</th>
</tr>
</ng-template>发布于 2021-12-20 15:40:45
尝试为PrimeNG table元素设置table-layout: auto;。对我来说很管用
https://stackoverflow.com/questions/58015516
复制相似问题