primeng icon indicating copy to clipboard operation
primeng copied to clipboard

Dynamic Sorting on data update?

Open RicardoVaranda opened this issue 10 years ago • 8 comments

Not sure if this feature is already available but I was not able to find it, it would be cool if the table would update the sorting if a value is changed on the column which are being sorted.

Edit: I see this is sort of implemented here: https://github.com/primefaces/primeng/issues/298

But for some reason it does not update the sorting, currently I am changing a value of an object inside of the value array and the changes do display properly but it does not update the sorting, would you be able to shine some light on how this can be achieved?

RicardoVaranda avatar May 02 '16 12:05 RicardoVaranda

Yup - we need some way to force the table to resort if we change contents. Doesn't seem to maintain sort correctly if we change the contents of the table content outwith the table.

GraemeSMiller avatar May 04 '16 14:05 GraemeSMiller

So to clarify, if the table is sorted already and the data is changed by you, you want the table to sort the new data? I believe we can do it.

cagataycivici avatar May 04 '16 21:05 cagataycivici

Yes. Exactly that. Alternative is a way to just apply sort again. I am changing data so can just reapply. However being lazy it would be nice if table just resorted on data change.

GraemeSMiller avatar May 04 '16 21:05 GraemeSMiller

Ok, we'll do it then.

cagataycivici avatar May 05 '16 10:05 cagataycivici

Thanks for the fix.

RicardoVaranda avatar May 05 '16 11:05 RicardoVaranda

Is this already implemented in primeng ? How can I resort the datatable if the data has changed?

arjayfuentes avatar Sep 10 '17 16:09 arjayfuentes

@arjayleviackerman24 i don't think, i am also looking for this fix.

marslan2037 avatar Dec 09 '17 07:12 marslan2037

@arjayleviackerman24 & @marslan2037 I faced the same issue and solved it like this:

updateMyTableData() {
    for (var i = 0, c = this.myTableData.length; i < c; i++) {
        this.myTableData[i].whatever = 'new data ' + i;
    }
    this.myTableData = [...this.myTableData]; // important: rebuild the array
}

Sources:

Table may need to be aware of changes in its value in some cases such as reapplying sort. For the sake of performance, this is only done when the reference of the value changes meaning a setter is used instead of ngDoCheck/IterableDiffers which can reduce performance. So when you manipulate the value such as removing or adding an item, instead of using array methods such as push, splice create a new array reference using a spread operator or similar. (PrimeNG docs)

https://github.com/primefaces/primeng/issues/2689#issuecomment-299407901

Hope it helps!

JimmyTheNerd avatar Apr 13 '18 13:04 JimmyTheNerd