PrimeNG Turbotable带有针对一列的自定义比较器?

时间:2019-03-06 15:22:55

标签: angular primeng primeng-turbotable

我们有一个很大的表,其中包含许多排序和过滤选项。该表可以按几列进行排序,尽管一次只能对其中一列进行排序。没有合并排序。

现在,我要添加一个包含小部件而不是文本的字段...可以理解的是,默认比较器跳闸了。因此,我想提供一个,但发现自己做不到。我发现的所有信息都涉及为整个表提供自定义(sortFunction),而我只需要为一个特定列提供一个。

为了让您了解外观,表结构是这样构建的:

<p-table [value]="items" ... >
  <ng-template pTemplate="header">
    <tr>
      <th [pSortableColumn]="'condition'"> Condition
        <p-sortIcon [field]="'condition'"></p-sortIcon>
      </th>
      <!-- other columns that look the same except for labels -->
    </tr>
  </ng-template>

  <ng-template pTemplate="body" let-item>
    <tr [pContextMenuRow]="item">
      <!-- this is the specific column I need custom sorting for -->
      <td><button type="button" pButton [label]="getConditionLabelFor(item)"
                  [ngClass]="getConditionClassFor(item)"></button>
      </td>
      <td>{{item.code}}</td>
      <!-- more columns that look exactly like the last one -->
    </tr>
  </ng-template>
</p-table>

我正在寻找的是一种将自定义比较器传递给<th [pSortableColumn]="field"的方法,或者类似的方法,而不是影响整个表的方法。这可能吗?

0 个答案:

没有答案