Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reset filter value on primeNG table

Tags:

primeng

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?

like image 244
Cosmin Ionascu Avatar asked Jul 18 '18 07:07

Cosmin Ionascu


People also ask

How to enable filtering on DataTable at different levels?

We can enabling filtering on datatable at different level, here are different options we have Global filtering : When the filter is applied on whole table level is called as global filtering Column filtering : When the filter is applied on a column level is called as Column filtering

What is filtermatchmode in angular primeng?

The filter function supports optional filter properties such as filterMatchMode to provide various forms of a search for text. It has 5 matching filter modes, such as In previous tutorial we had implemented Angular PrimeNG Datatable Paginator Example.

How do I filter a table in associatet?

the table filtering is triggered by the keyup-event in the associatet input-field. For example: <input #gb type="text" pInputText size="50" style="float:left" placeholder="Global Filter"> directly above it in the example.

How to do a hard reset of a table?

There is a reset method to do hard reset which can do by getting a local template variable instance of table.


1 Answers

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>
like image 122
Cosmin Ionascu Avatar answered Sep 21 '22 06:09

Cosmin Ionascu