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

PrimeNg Table Cannot assign to read only property '0' of object '[object Array] #15521

Open
ekrem-kocak opened this issue May 10, 2024 · 2 comments
Labels
Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible

Comments

@ekrem-kocak
Copy link

Describe the bug

In Angular 17.3 version, I'm using PrimeNG 17.15 version table. I'm constantly encountering the same error during sorting. To check if I'm making a mistake, I tried to implement it exactly as described in the documentation, but I still get the same error.

ERROR TypeError: Cannot assign to read only property '0' of object '[object Array]'
at Array.sort ()
at Table.sortSingle (primeng-table.mjs:1163:32)
at Table.sort (primeng-table.mjs:1101:18)
at SortableColumn.onClick (primeng-table.mjs:3601:21)
at SortableColumn_click_HostBindingHandler (primeng-table.mjs:3627:92)
at executeListenerWithErrorHandling (core.mjs:25630:16)
at wrapListenerIn_markDirtyAndPreventDefault (core.mjs:25664:22)
at HTMLTableCellElement. (platform-browser.mjs:679:17)
at _ZoneDelegate.invokeTask (zone.js:403:31)
at core.mjs:14556:55

Environment

Reproducer

No response

Angular version

17.3.0

PrimeNG version

17.15.0

Build / Runtime

Angular CLI App

Language

TypeScript

Node version (for AoT issues node --version)

20.12.2

Browser(s)

Chrome

Steps to reproduce the behavior

No response

Expected behavior

No response

@ekrem-kocak ekrem-kocak added the Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible label May 10, 2024
@imaksp
Copy link

imaksp commented May 11, 2024

Hi, you can check this live demo code from doc, it is working here:
https://stackblitz.com/run?file=src%2Fapp%2Ftable-single-column-sort-demo.html

@ekrem-kocak
Copy link
Author

I realized that the issue stemmed from the state management library (I'm using NGXS). As a solution, I utilized the @Input() value transform introduced with Angular 16.

image
image
image

You can opt for such a solution, or you can use the cloneDeep function from the lodash library. For versions of Angular prior to 16, my suggestion would be to use the following approach instead of @Select

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible
Projects
None yet
Development

No branches or pull requests

2 participants