Primeng: p-table modifies data array when sorting, errors on frozen array

Created on 25 Jan 2020  路  3Comments  路  Source: primefaces/primeng

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

[X] bug report => Search github for a similar issue or PR before submitting

Plunkr Case (Bug Reports)
I couldn't get the plunkr template to run karma tests... so here's a gist with a complete self-sufficient test case:
https://gist.github.com/HonoluluHenk/93ad431bb6185533334fed71d9e3faff

Current behavior

Sorting a p-table unexpectedly tries to modify the underlying data array.
Worse, this errors out on frozen arrays.

Probably related to #2630 and #2529

Expected behavior
Data should not be modified.

Minimal reproduction of the problem with instructions
Set the value of a p-table to a frozen array, define some sort column, run everything and click the sort header => exception thrown

What is the motivation / use case for changing the behavior?
Unexpected behavior, exception.

Please tell us about your environment:

  • Angular version: 8.X
  • PrimeNG version: 9.0.0-rc.3

All 3 comments

FYI, it happens for instance when you want to use ngrx observable with an async pipe directly.
If I have a table
<p-table [value]="datathreadResults$ | async">...

the following in TS聽file wont work with message :
this.datathreadResults$ = this.store.select(state => state.datathread.datathreadResults));

ERROR TypeError: "0 is read-only"
    sortSingle primeng-table.js:712
    ngOnChanges primeng-table.js:51

I'm currently adding a map operation to go around this issue :

this.datathreadResults$ = this.store.select(state => state.datathread.datathreadResults).pipe(map(datathread => [...datathread]));

Set [focusOnShow]="false" to disable auto focus of Dialog if you need to manage focus yourself.

@cagataycivici Uhm... Neither is this fixed nor is your comment relevant to the problem :(
Was your comment/closing the issue really meant?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

pchristou picture pchristou  路  3Comments

Helayxa picture Helayxa  路  3Comments

SchneMa picture SchneMa  路  3Comments

cyberrranger picture cyberrranger  路  3Comments

miresk picture miresk  路  3Comments