PrimeNg TurboTable colgroup 动态 colspan

Pun*_*han 1 primeng primeng-datatable angular5 primeng-turbotable

如何将变量分配给 primeng TurboTable ColGroup colspan 属性。

<ng-template pTemplate="header">
    <tr>
        <th rowspan="3">Brand</th>
        <th colspan="4">Sale Rate</th>
    </tr>
    <tr>
        <th colspan="colSpanCount">Sales</th>
        <th colspan="2">Profits</th>
    </tr>
    <tr>
        <th>Last Year</th>
        <th>This Year</th>
        <th>Last Year</th>
        <th>This Year</th>
    </tr>
</ng-template>
Run Code Online (Sandbox Code Playgroud)

在上面的示例中,我想将 colSpanCount 变量绑定到 p 表的 colspan 属性。

Pun*_*han 5

我想,我自己已经找到了答案。我们可以设置 [attr.colspan]="colSpanCount" 属性来动态设置 colspan。

<ng-template pTemplate="header">
    <tr>
        <th rowspan="3">Brand</th>
        <th colspan="4">Sale Rate</th>
    </tr>
    <tr>
        <th [attr.colspan]="colSpanCount">Sales</th>
        <th colspan="2">Profits</th>
    </tr>
    <tr>
        <th>Last Year</th>
        <th>This Year</th>
        <th>Last Year</th>
        <th>This Year</th>
    </tr>
</ng-template>
Run Code Online (Sandbox Code Playgroud)