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: Combined filter and sorting doesn't detect changes to datasource #17133

Open
mennolodder opened this issue Dec 19, 2024 · 1 comment
Labels
Resolution: Help Wanted Issue or pull request requires extra help and feedback
Milestone

Comments

@mennolodder
Copy link

Describe the bug

I have a p-table which is filled based on an api call. When changed the table ,for instance deleting a row, all data in the table is refreshed (the value bound to data is assigned with the results).

When I use a default sorting:

  sortField="enabledFrom"
  [sortOrder]="1"

And a text filter on a different column:

          <p-columnFilter 
              type="text" 
              field="message" 
              placeholder="Filter" 
              ariaLabel="message" 
              [showMenu]="false"
              [showClearButton]="false"
              />

Then deleting an item will not update the table, the deleted item is removed from the backend data, but no removed from the view. Changing the filter will remove it.

Manually triggering the filter from the component after changing the data does help (but it does break my global filter)
this.myTable['_filter']();

I believe this is a bug in the follow part of the code (ngOnChanges of p-table):

https://github.com/primefaces/primeng/blob/7f439a659a8e34d3b92ae1ad6366536229c6e36e/packages/primeng/src/table/table.ts#L1389C4-L1410C1

 ngOnChanges(simpleChange: SimpleChanges) {
        super.ngOnChanges(simpleChange);
        if (simpleChange.value) {
            if (this.isStateful() && !this.stateRestored && isPlatformBrowser(this.platformId)) {
                this.restoreState();
            }

            this._value = simpleChange.value.currentValue;

            if (!this.lazy) {
                this.totalRecords = this._value ? this._value.length : 0;

                if (this.sortMode == 'single' && (this.sortField || this.groupRowsBy)) this.sortSingle();
                else if (this.sortMode == 'multiple' && (this.multiSortMeta || this.groupRowsBy)) this.sortMultiple();
                else if (this.hasFilter())
                    //sort already filters
                    this._filter();
            }

            this.tableService.onValueChange(simpleChange.value.currentValue);
        }

The ' else if (this.hasFilter())' only applies the filter if there is no sorting, but should apply it regardless (I can't tell if thee are any other replies).

Environment

Tested with: primeng 17.18.2

Checked code for 17.18.15 and 18.0.1 both contain this.

Reproducer

No response

Angular version

18.0.5

PrimeNG version

17.18.2, and later

Build / Runtime

Angular CLI App

Language

TypeScript

Node version (for AoT issues node --version)

18.0.1

Browser(s)

No response

Steps to reproduce the behavior

No response

Expected behavior

No response

@mennolodder mennolodder added the Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible label Dec 19, 2024
@mertsincan mertsincan added Resolution: Help Wanted Issue or pull request requires extra help and feedback and removed Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible labels Dec 19, 2024
Copy link

Due to PrimeNG team's busy roadmap, this issue is available for anyone to work on. Make sure to reference this issue in your pull request. ✨ Thank you for your contribution! ✨

@mertsincan mertsincan added this to the Future milestone Dec 19, 2024
@github-project-automation github-project-automation bot moved this to Review in PrimeNG Dec 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Resolution: Help Wanted Issue or pull request requires extra help and feedback
Projects
Status: Review
Development

No branches or pull requests

2 participants