问题:primeng:冻结列不适用于动态列。
代码详情:
检查下面的代码:
app.component.html:
<div class="card">
<h5>Frozen Columns</h5>
<p-table [columns]="scrollableCols" [frozenColumns]="frozenCols" [value]="customers" [scrollable]="true" scrollHeight="200px" frozenWidth="300px">
<ng-template pTemplate="colgroup" let-columns>
<colgroup>
<col *ngFor="let col of columns" style="width:300px">
</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-customer let-columns="columns">
<tr>
<td *ngFor="let col of columns">
{{customer[col.field]}}
</td>
</tr>
</ng-template>
</p-table>
</div>
app.component.ts
import { Component } from '@angular/core';
import { CustomerService } from './customerservice';
import { Customer } from './customer';
import { FilterUtils } from 'primeng/utils';
import { LazyLoadEvent } from 'primeng/api';
import { SelectItem } from 'primeng/api';
import { MessageService } from 'primeng/api';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
providers: [MessageService]
})
export class AppComponent {
customers: Customer[];
scrollableCols: any[];
frozenCols: any[];
constructor(private customerService: CustomerService) {}
ngOnInit() {
this.customerService.getCustomersLarge().then(data => {
this.frozenCols = [{ field: 'name', header: 'Name' }]; // assume this column will come from database
this.customers = data;
this.scrollableCols = [
{ field: 'id', header: 'Id' },
{ field: 'date', header: 'Date' },
{ field: 'company', header: 'Company' },
{ field: 'status', header: 'Status' },
{ field: 'activity', header: 'Activity' }
]; // assume this column will come from database
});
}
}
OUTPUT:冻结列和解冻列不在同一行显示。
请帮我找到解决方案。