2

We're having a pretty large table with lots of sorting and filtering options. The table is sortable by several columns, though only for one of them at a time. There's no combined sorting going on.

Now I am adding a field that contains a small widget instead of just text... Which understandably trips up the default comparator. So I'd like to provide one, but find myself unable to do so. All the info I find refer to providing a custom (sortFunction) for the entire table, while I only need one for one specific column.

To give you an idea what things look like, The table structure is built up like this:

<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>

What I'm looking for is some means to pass a custom comparator to <th [pSortableColumn]="field" or something along those lines, not something that affects the entire table. Is this somehow possible?

UncleBob
  • 1,233
  • 3
  • 15
  • 33

0 Answers0