[FIXED] Reset filter value on primeNG table

Issue

According to the documentation from https://www.primefaces.org/primeng/#/table the reset method should “Resets sort, filter and paginator state.”
The problem is that reset table method is not deleting the filters from UI. (although filters field from table.ts is {} after reset)

Please see the this where I reproduced it.
The code can be seen here
Filter the Summary table (see example) by Failed field (or any other field).
Press reset. => The table values will be reset but the filter value will still be visible.

The example is with the basic table but it’s also NOT working with dynamic cols.

<ng-template pTemplate="header" let-columns>
<tr>
  <th *ngFor="let col of columns" [pSortableColumn]="col.field">
    {{col.header}}
    <p-sortIcon [field]="col.field"></p-sortIcon>
  </th>
</tr>
<tr>
  <th *ngFor="let col of columns">
    <input pInputText type="text" (input)="dt.filter($event.target.value, col.field, 'contains')">
  </th>
</tr>

Do you have any ideea on how I can clear the filters from the inputs?

Solution

Fixed it here

For input fields just add

[value]="dt.filters[<field>] ? dt.filters[<field>].value : ''" 

where <field> is the field send in the (input) method.

 (input)="dt.filter($event.target.value,<field>, 'contains')"

For example:

    <th>
      <input pInputText type="text" (input)="dt.filter($event.target.value, 'date', 'contains')"
       [value]="dt.filters['date'] ? dt.filters['date'].value : ''">
    </th>

Answered By – Cosmin Ionascu

Answer Checked By – Robin (Easybugfix Admin)

Leave a Reply

(*) Required, Your email will not be published