Sorting in List ViewPosted: June 11, 2012
In the previous article, I documented a tidy and portable way to sort portals by clicking on column labels. In the interests of consistency (the user doesn’t know or care whether s/he’s looking at a portal or a list), it makes sense to have the same functionality on List View layouts – i.e.
- click on the column label to do the sort,
- reverse the sort direction if user clicks ion the same column twice,
- and have a little arrow-head to indicate which column is sorted, and in which direction.
To do this in FOCUS, we have a couple of scripts, performed by a controlling script, i.e. “Sort a list”. So when user clicks on a column heading, the button performs “Sort a list”, with the field name passed as a parameter.
“Set list sort direction” basically takes the parameter onwards, and compares it with how the last list sort was done. If that was on the same field, we reverse the direction, using a Boolean global variable. Note the use of the “Abs” function to set the direction to “1” after the toggling may have set it to “-1”.
“Perform list sort” does the actual sort, based on the context and direction we’ve set. Note that there’s a pair of “sort” script steps for each clickable column, one ascending and one descending. Note also that this script deals with all clickable columns on all relevant list layouts.
On the layout itself, we just need conditionally formatted arrowheads to show on which field the list is sorted, and in which direction.