PrimeNG Angular Table "Converting circular structure to JSON" whenever table data contains non-trivial data #14428
Labels
Status: Needs Triage
Issue will be reviewed by Core Team and a relevant label will be added as soon as possible
Describe the bug
Our application uses template components in its table. These components are given a reference to their own AbstractControl for various reasons. The problem is, that as result these components are being stored in the
selected
property of the PrimeNG table when user selects a row.Then, when the user clicks on a row,
Table.handleRowClick()
is being called.Table.handleRowClick()
callsTable.saveState()
which tries toJSON.stringify()
onTable.selected
.JSON.stringify()
doesn't like so much AbstractControls (and RXJS Subjects, which are also useful to pass to some table components) as they contain circular references internally. This raises an exception, and the state is not saved.One could argue we should only store pure data in our
table.data
property, but it is many times important to pass more complex structures to the components. And with current implementation this breaks thehandleRowClick()
call.A simple solution - pass a circular handler to JSON.stringify() as so:
Environment
Angular 16.1.7 in browsers web site.
Reproducer
No response
Angular version
16.1.7
PrimeNG version
16.1.0
Build / Runtime
TypeScript
Language
TypeScript
Node version (for AoT issues node --version)
18.18.2
Browser(s)
Chrome 120.0.6099.129
Steps to reproduce the behavior
The result -> exception in the console log.
Expected behavior
The state is saved without exception.
The text was updated successfully, but these errors were encountered: