-
Notifications
You must be signed in to change notification settings - Fork 4.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
p-table reset() causes errors in filter value binding #9570
Comments
Same problem detected here with 11.0.0 It seems that model for the filter is stored directly in filters object of the table primeng/src/app/components/table/table.ts Line 4096 in b04aa55
Then when table is cleared after reset model is destroyed... From the UI, it can be recovered by clicking on clear button on the column filter menu, but programatically it seems to be difficult to implement a workaround (clear method should be executed on each column filter instance). |
Just wanted to report the same and created a Stackblitz case, then found this issue. Here is my Stackblitz if it helps: https://primeng-issue-9750.stackblitz.io The problem still exists in PrimeNG 11.1.0. I think it is caused by changing the |
I'm currently using the following workaround: in the template: <p-table #table ...>
<ng-template pTemplate="header">
<tr><th>heading</th>...<tr>
<tr *ngIf="showFilters"><th>filter</th></tr>
</ng-template>
...
</p-table> in the component: showFilters = true;
@ViewChild('table') table: Table;
constructor(private cd: ChangeDetectorRef) { }
resetTable(): {
this.showFilters = false;
this.cd.detectChanges();
table.reset();
table.saveState();
this.showFilters = true;
this.cd.detectChanges();
} I.e. I remove the filters temporarily while resetting the table and add them back afterwords. This will instantiate the filter components newly and they will work just fine. The problem only appears if you reset the table while the filter components are still alive. |
Another issue is here:
For the default Inputs the filterContraint is optionally chained. For the filterTemplate not, which causes another error when resetting the table state. |
this.table.filters = {}; add this above of table clear or reset |
Thank you @sadnahu !! I don't understand what's going on enough to reopen this or enter a new bug, but even after upgrading to 13.3.3 I was still getting an error in on ModelChange() when typing in the filter's input box:
since this.filterConstraint was undefined. After adding Sadnahu's line of code, the filter is working. |
I'm submitting a ... (check one with "x")
Plunkr Case (Bug Reports)
https://primeng-tablefilter-demo-h7jrf9.stackblitz.io/
Current behavior
Calling reset on the p-table causes the value for columnfilters to generate an error
Expected behavior
No error
Minimal reproduction of the problem with instructions
Click Reset Filters on stackblitz
Primeng 11.0.0-rc1
The text was updated successfully, but these errors were encountered: