My requirement is to sort the records of a table on the SKUID page in descending order, based on a UI only field(Age field, as shown in the screenshot):
I have tried adding the UI only field ID in the “Fields to order records by” on the Model level, which throws an error:
The error:
I have also tried adding an Event for sorting the model, when the Skuid page is rendered, as shown in the screenshots:
This works when the page is rendered, but in my case the page is loaded twice to activate the “SLS I” and “SLS II” buttons on the page, as shown. Due to this, the records are unsorted again when the page finally loads.
This can be a bit tricky to do, but I think you want an action when Model Requeried that sorts the model by the UI-Only field. What’s tricky is that model sorting (even client-side) triggers the Model Requery action, so it’s easy to get stuck in a loop. What I usually do is have a checkbox I check just before I sort the model that, then have a branch at the beginning of the model actions that says ‘hey don’t run these actions if that box is checked.’ It looks something like this:
This works for my case, but I found another way to work on the same:
I tried adding “Sort Model” in “Actions” for the tab which leads to this Skuid page, which sorts the records as expected, on loading the page.
But, after applying filters, i.e., clicking on “SLS I” or “SLS II” buttons on the page, the records get unsorted again.
I am trying to add actions on model level for the same, which is not working for my requirement as of now. So, I have placed a “Sort by Age” Global action on the page, as visible in the screenshot. I am still trying to find out a better way to make it work with filters.
If you want the model to always ‘default’ sorting by the UI field, I think you need to have it in the model action when model requeried.
What happens now is something roughly like this:
When they open the tab, your sort actions happens
Table gets sorted by Age
They choose a filter, model gets requeried as part of filtering
When querying, it uses the last known server side sorting (in your case, the M0_Approvals_Request… info in the Fields to order records by property)
If a sort button will do the trick, that’s a great solution to give users. If it needs to automatically sort by the UI field whenever its queried, then you need to have some actions in the Model Requeried area to handle sorting. As far as I know, it’s the only way to ensure it happens every time the model is queried.
Thanks for the reply and apologies for the late response!
About Actions when model is requeried, I tried the solution, but the filter gets applied after the model is queried. So the sorting logic gets overwritten and the records get unsorted again.