When app maker creates a table it can make the columns sortable, which is great, but after a user clicks on a column, how can you clear that sort setting to get the table back to either the default settings from when the page first loaded or a specific sort order as in the script below? I am presently using a Refresh button which merely reloads the datasource, but the column sorting remains. Suggestions?
I have tried reloading or navigating back to the page itself, but that had no effect either.
this is the augmented Refresh onClick script that includes the sort order:
widget.datasource.query.sorting.App._ascending();
widget.datasource.query.sorting.Role._ascending();
widget.datasource.query.sorting.Name._ascending();
widget.datasource.load();
Morfinismo gave me the code fragment I was missing, but here's the breakdown:
This will reset any filters and clear out filter fields like dropdowns or suggest boxes:
widget.datasource.query.clearFilters();
This will clear any sorting, so if you want sorting, you will need to add it like so:
widget.datasource.query.clearSorting();
widget.datasource.query.sorting.App._ascending();
widget.datasource.query.sorting.Role._ascending();
widget.datasource.query.sorting.Name._ascending();
which will clear the sorting and reset it to your liking, but will not remove the little arrow graphic on the column heading. For that you will need to navigate back to the page you are already on to refresh it like this:
app.showPage(app.pages.AppRoles);
Here is the complete Refresh button onClick script:
app.showPage(app.pages.AppRoles);
widget.datasource.query.clearFilters();
widget.datasource.query.clearSorting();
widget.datasource.query.sorting.App._ascending();
widget.datasource.query.sorting.Role._ascending();
widget.datasource.query.sorting.Name._ascending();
widget.datasource.load();
This worked for me, but I'm sure there are other approaches and tricks of the trade. Feel free to post them here for future answer seekers.