我目前正在使用具有卡住列功能的 PrimeNG 表控件。
一切正常,我能够获得卡住列,但现在我想修改我的卡住和解冻列样式以及我在下面使用的属性的自定义列宽度。
代码:
<p-table [columns]="scrollableCols" [frozenColumns]="frozenCols" [value]="cars" [scrollable]="true" scrollHeight="300px" frozenWidth="250px">
<ng-template pTemplate="colgroup" let-columns>
<colgroup>
<col style="width:200px">
<col style="width:50px">
<col style="width:100px">
<col style="width:100px">
<col style="width:100px">
<col style="width:100px">
</colgroup>
</ng-template>
<ng-template pTemplate="header" let-columns>
<tr>
<th *ngFor="let col of columns">
{{col.header}}
</th>
</tr>
</ng-template>
<ng-template pTemplate="body" let-rowData let-columns="columns">
<tr>
<td *ngFor="let col of columns">
{{rowData[col.field]}}
</td>
</tr>
</ng-template>
</p-table>
通过使用宽度,我能够实现列的宽度,但对于前两列,卡住和解冻列表都会自动为所有两列采用相同的宽度,我想在卡住和解冻中分配不同大小的列解冻列 s。
是否可以为卡住和解冻列添加不同的大小?
最佳答案
您所需要的只是pTemplate="frozencolgroup"
<ng-template pTemplate="frozencolgroup" let-columns>
<colgroup>
<col style="width:200px">
<col style="width:50px">
</colgroup>
</ng-template>
<ng-template pTemplate="colgroup" let-columns>
<colgroup>
<col style="width:100px">
<col style="width:100px">
<col style="width:100px">
<col style="width:100px">
</colgroup>
</ng-template>
演示 here
更新:使用滚动表可以打破行高。下面的提示函数可以解决这个问题
makeRowsSameHeight() {
setTimeout(() => {
if ($('.ui-table-scrollable-wrapper').length) {
let wrapper = $('.ui-table-scrollable-wrapper');
wrapper.each(function () {
let w = $(this);
let frozen_rows: any = w.find('.ui-table-frozen-view tr');
let unfrozen_rows = w.find('.ui-table-unfrozen-view tr');
for (let i = 0; i < frozen_rows.length; i++) {
if (frozen_rows.eq(i).height() > unfrozen_rows.eq(i).height()) {
unfrozen_rows.eq(i).height(frozen_rows.eq(i).height());
} else if (frozen_rows.eq(i).height() < unfrozen_rows.eq(i).height()) {
frozen_rows.eq(i).height(unfrozen_rows.eq(i).height());
}
}
});
}
});
}
更新演示:https://stackblitz.com/edit/angular-primeng-table-frozen-columns-dpsm8l
关于css - 如何在primeng中的卡住和解冻列表中设置不同的列样式和宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54182165/