Skip to content
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

Closed
jimmycartrette opened this issue Nov 24, 2020 · 6 comments
Closed

p-table reset() causes errors in filter value binding #9570

jimmycartrette opened this issue Nov 24, 2020 · 6 comments
Assignees
Labels
Type: Bug Issue contains a bug related to a specific component. Something about the component is not working
Milestone

Comments

@jimmycartrette
Copy link

I'm submitting a ... (check one with "x")

[ X] bug report => Search github for a similar issue or PR before submitting
[ ] feature request => Please check if request is not on the roadmap already https://github.com/primefaces/primeng/wiki/Roadmap
[ ] support request => Please do not submit support request here, instead see http://forum.primefaces.org/viewforum.php?f=35

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 version: 5.X
    Primeng 11.0.0-rc1
@yigitfindikli yigitfindikli added the Status: Pending Review Issue or pull request is being reviewed by Core Team label Nov 25, 2020
@yigitfindikli yigitfindikli added this to the 11.0.1 milestone Nov 25, 2020
@yigitfindikli yigitfindikli self-assigned this Nov 25, 2020
@yigitfindikli yigitfindikli modified the milestones: 11.0.0-Final, 11.0.1 Dec 7, 2020
@ips219
Copy link

ips219 commented Jan 4, 2021

Same problem detected here with 11.0.0

It seems that model for the filter is stored directly in filters object of the table

this.dt.filters[this.field] = this.display == 'row' ? {value: null, matchMode: defaultMatchMode} : [{value: null, matchMode: defaultMatchMode, operator: this.operator}];

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).

Screenshot_3
Screenshot_2

@yigitfindikli yigitfindikli added Type: Bug Issue contains a bug related to a specific component. Something about the component is not working and removed Status: Pending Review Issue or pull request is being reviewed by Core Team labels Jan 8, 2021
@yigitfindikli yigitfindikli modified the milestones: 11.1.0, 11.2.0 Jan 11, 2021
@Cito
Copy link
Contributor

Cito commented Jan 19, 2021

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 filterConstraint that is an input for the ColumnFilterFormElement, but it has no ngOnChange to notice that change.

@yigitfindikli yigitfindikli modified the milestones: 11.2.0, 11.3.0 Jan 21, 2021
@Cito
Copy link
Contributor

Cito commented Jan 25, 2021

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.

@denny99
Copy link
Contributor

denny99 commented Feb 11, 2021

Another issue is here:

<ng-container *ngTemplateOutlet="filterTemplate; context: {$implicit: filterConstraint.value, filterCallback: filterCallback}"></ng-container>
</ng-container>
<ng-template #builtInElement>
    <ng-container [ngSwitch]="type">
        <input *ngSwitchCase="'text'" type="text" pInputText [value]="filterConstraint?.value" (input)="onModelChange($event.target.value)"

For the default Inputs the filterContraint is optionally chained. For the filterTemplate not, which causes another error when resetting the table state.

@sadnahu
Copy link

sadnahu commented Jan 14, 2022

this.table.filters = {}; add this above of table clear or reset

@danbanswer
Copy link

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:

    onModelChange(value) {
        this.filterConstraint.value = value;

since this.filterConstraint was undefined. After adding Sadnahu's line of code, the filter is working.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Issue contains a bug related to a specific component. Something about the component is not working
Projects
None yet
Development

No branches or pull requests

7 participants