[FIXED] Reset filter value on primeNG table


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>
  <th *ngFor="let col of columns" [pSortableColumn]="col.field">
    <p-sortIcon [field]="col.field"></p-sortIcon>
  <th *ngFor="let col of columns">
    <input pInputText type="text" (input)="dt.filter($event.target.value, col.field, 'contains')">

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


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:

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

Answered By – Cosmin Ionascu

Answer Checked By – Robin (Easybugfix Admin)

Leave a Reply

(*) Required, Your email will not be published