PrimeNg TurboTable - 条件行分组

问题描述 投票:1回答:1

我正在使用PrimeNG的TurboTable(p表)

我有一个groupField参数,可以是null或者具有与列标题对应的值。此参数的值可以随时动态更改。预期的行为是,当groupField==null呈现正常表但是'groupField ==`时,行按照此值进行分组,如here所示。

我想实现here所描述的行分组,其中表响应groupField参数的变化。

我尝试过的:

  1. 使用pTemplate="body"创建两个ng-templates,就像这样。
<ng-template pTemplate="body" *ngIf="groupField==null">
    ...
<ng-template>
<ng-template pTemplate="body" *ngIf="groupField!=null">
    ...
<ng-template>
<ng-template pTemplate="rowexpansion" *ngIf="groupField!=null">
    ...
<ng-template>

这不起作用,因为我怀疑p-table在首次渲染时形成其配置,随后只更新数据。

  1. 制作两个不同的<p-table>s,一个带有行组,另一个没有,用ngIf来控制哪一个在给定时间显示。这有效,但对我没有意义,因为我应该能够在一张桌子上做到这一点,因为我能够在旧的<p-datatable>

我想要的是让一个表处理所有这些。

angular primeng primeng-datatable primeng-turbotable
1个回答
0
投票

你可以在你的<ng-container>中添加一个<p-template>,所以它看起来像这样:

<ng-template pTemplate="body">
   <ng-container *ngIf="groupField==null">
    ...
   </ng-container>
   <ng-container *ngIf="groupField!=null">
    ...
   </ng-container>
<ng-template>
<ng-template pTemplate="rowexpansion" *ngIf="groupField!=null">
    ...
<ng-template>

你可以在这里查看它:

https://stackblitz.com/edit/angular-primeng-stack-55706959?file=src/app/ils-tree/ils-tree.component.ts

有一个groupField,您可以在tablegrouping.component.ts中从true更改为false以检查其工作原理。

© www.soinside.com 2019 - 2024. All rights reserved.