Bug: table reset does not reset sorting
[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
Plunkr Case (Bug Reports) Please demonstrate your case at stackblitz by using the issue template below. Issues without a test case have much less possibility to be reviewd in detail and assisted.
https://stackblitz.com/edit/primeng-tablesort-demo-tyz3n8
Current behavior
Build sortable table, make a column the default sorted column.
Sort on another column.
Click the reset button, performs a table.reset().
Keeps the current sort order.
Expected behavior After clicking the reset button, the sort order should revert back to the default sort column defined on the table.
Minimal reproduction of the problem with instructions
Open the StackBlitz example.
Notice the sort order is the Name column.
Sort by any other column.
Click the reset button.
Nothing happens
What is the motivation / use case for changing the behavior? I want to reset the sort order to the default sort order. The table documentation tells me that it should work as intended: reset(): Resets sort, filter and paginator state.
Please tell us about your environment: OS: Windows 10 IDE: WebStorm/VS Code Package manager: npm Http server: node
-
Angular version: 5.X 12.2.2
-
PrimeNG version: 5.X 12.1.0
-
Browser: [all | Chrome XX | Firefox XX | IE XX | Safari XX | Mobile Chrome XX | Android X.X Web Browser | iOS XX Safari | iOS XX UIWebView | iOS XX WKWebView ] Edge, Chrome, Brave, FireFox (this one comes from testers).
-
Language: [all | TypeScript X.X | ES6/7 | ES5] typescript 4.3.5
-
Node (for AoT issues):
node --version=
16.2.0
Same issue with 13.3.3
table.clear() (which is same as table.reset()) does not restore the table's original sort order, though it does clear the sort icons in the header row. It does reset the filter state correctly.
This should also work even if there is no default sort column. This happens for either single or multiple sort modes.
For those still on this, I found an ugly workaround:
First, we need a Viewchild that gives use access to the table from the view.
Then we trigger the sort function, with specific parameters. To control the order, I choose to send the sortOrder to the opposite of what I need, and the sortFilter to the wanted sortField. It will be reversed by the sort function.
So this looks like this :
this.table.reset()
this.table.sortOrder = -1;
this.table.sortField = "name";
this.table.sort({field: 'name'})
In this case, the reset function clears the icon from the header, and restore the sorting to my default sorting by name.
This is ugly, and I post this here to help people stuck on this, and also so that I can be informed when this is fixed.
Edit: If needed, I can set up a stackblitz to illustrate the issue. This issue is till valid for Angular 13 & Primeng 13.4.1
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,