PowerApps List Sorting
A feature that AMT has been including in our PowerApps for clients for a while is the inclusion of allowing the user to sort their list data and presenting it in a gallery control.
This feature has been implemented by setting an initial state on screen, visible:
This will set the initial sorting by client name and ascending.
Then the interactivity has been achieved by adding an icon next to each sortable control. These have been configured with the icon property dynamically set depending on the sort by and sort direction.
This sets it to the bi-directional arrow if it has not been selected, then either an up or down arrow depending on the sort order.
Finally, the onSelect property is set to change the ‘sort by’ and set an initial ascending sort order of ascending, if we are changing the selected sort by column. Or just swap the ‘sort by’:
These components all function as expected and provide a nice clean user interface, where the user’s expected interaction is conveyed to the user.
The problem comes when implementing the list itself.
Our first attempts at implementing this feature displayed the dreaded yellow exclamation mark of Delegation Warning.
The query that was used was, as one might expect:
To sort the list by the ‘sort by’ and sort direction variables.
Unfortunately, this produces something that PowerApps is unable to delegate to SharePoint, so we only receive the delegation limit number of results back.
Several alternatives were tried to remove this warning, none of them particularly pretty:
The final solution, one I am not particularly happy with at the moment is:
Although, we couldn’t pass the ‘sort by’ using an if statement as in a previous attempt, it was possible to pass the sort direction that way. This saved a lot of work by not having to repeat the SortByColumns function call for each sort by and direction.
This can be tidied up quite a lot by changing the locSortDirection variable for a Boolean value, which created the following:
Sort icon’s OnSelect:
Sort icon’s Icon:
With this setup, delegation works and your gallery control will load all data, paged, as you scroll down, 100 items at a time.