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?
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
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.
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.
There is a reset method to do hard reset which can do by getting a local template variable instance of table.
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With