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

DataTable: Infinite loop onValueChange #5160

Closed
patrickalcomendas opened this issue Oct 26, 2023 · 9 comments · Fixed by #5282
Closed

DataTable: Infinite loop onValueChange #5160

patrickalcomendas opened this issue Oct 26, 2023 · 9 comments · Fixed by #5282
Labels
Type: Bug Issue contains a defect related to a specific component.
Milestone

Comments

@patrickalcomendas
Copy link

patrickalcomendas commented Oct 26, 2023

Describe the bug

When enabling Row Group on DataTable and adding a filter, onValueChange loops infinitely if you try to store the data that is being passed.

image

Reproducer

https://codesandbox.io/p/sandbox/primereact-demo-forked-8nt3cw

PrimeReact version

10.0.5

React version

17.x

Language

ES6

Build / Runtime

Create React App (CRA)

Browser(s)

No response

Steps to reproduce the behavior

  1. Fork https://codesandbox.io/s/8kd8w6.
  2. Add a filter on the Country column.

image

  1. Create a function for onValueChange callback to store the data.

image

  1. Enable onValueChange callback by passing a function from step 3.

image

Expected behavior

The data that is being rendered by the datable should be available for processing. I need to get the filtered data in order to get the total of a column and display it in rowGroupFooterTemplate.

@patrickalcomendas patrickalcomendas added the Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible label Oct 26, 2023
@melloware melloware added Type: Bug Issue contains a defect related to a specific component. and removed Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible labels Oct 26, 2023
@melloware
Copy link
Member

I don't think you can do this. You are getting OnValueChange then changing the value of the Table which causes a re-render of the table which triggers your onValueChange which triggers a re-render....

@melloware melloware added Resolution: By Design The behavior in the issue is by design and the component exhibits the expected behavior and removed Type: Bug Issue contains a defect related to a specific component. labels Oct 26, 2023
@patrickalcomendas
Copy link
Author

@melloware the code replicator is not updating the value of the table back. The OnValueChange is calling a function setFilteredData to get current value rendered by the Table. setFilteredData is just setting filteredData and is not doing anything to filteredData at all after being set.

I understand that it will loop infinitely if I set the value of table back in OnValueChange, but that is not what I am doing. I will not be changing the value of the table, I just want to capture the changes after filtering, then render the footer (rowGroupFooterTemplate) of the rowGroup with type of subheader which is not going to change the value of the table.

image

image

@melloware melloware added Type: Bug Issue contains a defect related to a specific component. and removed Resolution: By Design The behavior in the issue is by design and the component exhibits the expected behavior labels Oct 27, 2023
@melloware
Copy link
Member

Thanks let me take a closer look.

@melloware
Copy link
Member

Interesting it doesn't happen in NextJS when I replicated your scenario but I can definitively see the error in CRA.

@FAMSTM
Copy link

FAMSTM commented Oct 31, 2023

Hi, I have a similar bug with 10.0.7 by using onValueChange to count the filtered rows (table goes back quickly to all data after filtering, or goes in infinite loop after sorting). Does anybody has a workaround to count the displayed rows after filtering?

@patrickalcomendas
Copy link
Author

Interesting it doesn't happen in NextJS when I replicated your scenario but I can definitively see the error in CRA.

I tried it with NextJS as well, but the issue persists.

@melloware
Copy link
Member

Weird I run your scenario in the NextJs showcase and it doesn't happen.

@patrickalcomendas
Copy link
Author

patrickalcomendas commented Nov 9, 2023

Do you still have the codebox? I will double-check it against my code if I miss something.

@melloware
Copy link
Member

No what I did was take your example and then in the PrimeReact showcase replicated your scenario which is Next 12 and I couldn't get it to infinite loop.

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

Successfully merging a pull request may close this issue.

3 participants