primeng icon indicating copy to clipboard operation
primeng copied to clipboard

Restoring table state does not restore sorting if a default sortField and sortOrder are set.

Open ThomasPrikrylBE opened this issue 5 years ago • 11 comments

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

[x] bug report => Search github for a similar issue or PR before submitting
[ ] feature request => Please check if request is not on the roadmap already https://github.com/primefaces/primeng/wiki/Roadmap
[ ] support request => Please do not submit support request here, instead see http://forum.primefaces.org/viewforum.php?f=35

Stackblitz (Bug Reports) I have taken the default state restoring example from this page: link And all I have changed is that I have added a default sortField and sortOrder (line 4.): sortField="name" [sortOrder]="-1"

Here is the edited stackblitz: https://stackblitz.com/edit/primeng-tablestate-demo-zyy7qj

Current behavior

  1. I enter the page for the first time and see a default sortField/Order set. (e.g. 'name')
  2. I change the sorting to 'country'.
  3. I filter by name 'james'
  4. I refresh the page
  5. The table will be sorted by the original/default sortField ('name') again.

Expected behavior

  1. I enter the page for the first time and see a default sortField/Order set. (e.g. 'name')
  2. I change the sorting to 'country'.
  3. I filter by name 'james'
  4. I refresh the page
  5. The table will be sorted by the last used sortField ('country').

Minimal reproduction of the problem with instructions If you remove this: sortField="name" [sortOrder]="-1" on line 4 in the stackblitz and the view refreshes, it will automatically jump back to sorting by country, if you have sorted by country before. This shows that the default sortField overrules the restored sorting field.

What is the motivation / use case for changing the behavior? I want to have an initial sortField and sortOrder so that the visible filter matches my lazy loaded table content (I am sorting by a specific field by default and to help the user understand what's going on, I want this filter to be highlighted from the beginning, this - afaik - is only possible by using the default sorting field/order) BUT I want this default behavior to be overruled in case the table was restored from an earlier state, because the user has already changed filters/sorting

  • Angular version: 12

  • PrimeNG version: 12

ThomasPrikrylBE avatar Oct 18 '21 10:10 ThomasPrikrylBE

I am working on a workaround (by setting the initial ordering manually) and I stumbled over a question: Let's say I am using lazy loading but i have lazyLoadOnInit=false. Then I am assuming the (onRestore) function will be called at some point, but how do I know - beforehand - if it WON'T be called eventually (because it is the user's first time on the page for example) - so that I can trigger the initial loading manually (e.g. in ngOnInit of the component that contains the table)?

ThomasPrikrylBE avatar Oct 18 '21 14:10 ThomasPrikrylBE

Have the same issue. Ended up in doing something on my own...

majkers avatar Feb 21 '22 07:02 majkers

I have the same problem. Managed to make it work with a custom workaround, but would be great to be able to use default sort field and sort order with state storage.

pete4dev avatar Aug 26 '22 10:08 pete4dev

Hi,

So sorry for the delayed response! Improvements have been made to many components recently, both in terms of performance and enhancement. Therefore, this improvement may have been developed in another issue ticket without realizing it. You can check this in the documentation. If there is no improvement on this, can you reopen the issue so we can include it in our roadmap? Please don't forget to add your feedback as a comment after reopening the issue. These will be taken into account by us and will contribute to the development of this feature. Thanks a lot for your understanding!

Best Regards,

mertsincan avatar Nov 09 '22 20:11 mertsincan

@ThomasPrikrylBE can You please verify it? I think it still exists in 14.2.1 version

majkers avatar Nov 10 '22 08:11 majkers

Have the same issue in 14 version( If I have [sortField]="'someField'" - restoring sortField from state is not working

Tilesto avatar Dec 07 '22 10:12 Tilesto

I can confirm this is still an issue.

image

It is related to the ngOnChanges function. It detects if a value is used as property. Then it restores the state, which will load the previous order of the table. Some lines later it will just overwrite the sortMeta if the multiSortMeta input was set.

So it might be better to restore the state AFTER everything else was set?

denny99 avatar Jan 30 '23 14:01 denny99

Same issue in 17 version.

danilofd avatar Feb 29 '24 02:02 danilofd

same here also on the latest v17

ilkomiliev avatar Mar 24 '24 18:03 ilkomiliev

Still facing the issue in the latest v17

elinagilevich avatar Jul 24 '24 06:07 elinagilevich

Hi,

So sorry for the delayed response! Improvements have been made to many components recently, both in terms of performance and enhancement. Therefore, this improvement may have been developed in another issue ticket without realizing it. You can check this in the documentation. If there is no improvement on this, can you open a new issue so we can include it in our roadmap?

Thanks a lot for your understanding! Best Regards,

mehmetcetin01140 avatar Dec 16 '24 11:12 mehmetcetin01140