The Separation Model – Part 9 – Sorting Elegance

For anyone who has worked with FileMaker for more than few years, the limitations found in the sorting script step are simply "the way it is". You can't dynamically specify either a sort field or the direction based on a calculated value or variable - like you can with the output path of an export for example.

These limitations have always been something to work around and overcome. Over the years, I've used many different methods for sorting. They typically always centered around the script which was used for handling the sort.

It's always been easy to add as much logic as required to a script, but making things as easy as possible and portable has always been the holy grail. I mean really, who wants to keep coming up with a new way to manage sorting list views and portals when you've got a solution to build. This stuff should just be built in.

Of course, part of the fun and appeal of FileMaker is the fact that it's like a puzzle and it always seems to present that worthy little challenge. So consider this video an answer to that challenge.

In this video, you'll learn, and have access to, what I consider to be one of the most elegant ways to managing sorting list views. If having your list views (and portals) provide the same features that every desktop user has grown used, (e.g. sorting columns and indicating direction) then you owe it to yourself to get this one down. It's just way too elegant and way too easy to implement once you've got the basics!

AttachmentSize
KarateAppPart9.zip242.2 KB

Comments

You mention in the video about applying this to portals. But give no indication as to how this is done....

I simply use the same functions for portals by duplicating them and then changing the namespace of the variables. They become something like $$SORT.PORTAL.[object_name].*

I hope that helps out.

-- Matt Petrowsky - ISO FileMaker Magazine Editor

How do you get around the limitation of not being able to sort a portal via a script? Or do you use a different (sounds like hidden tab panels) sorting technique but replace the actual sorts with a go to object name script step?

Could you please explain in more detail how you would implement the same solution for portals?
Probably a second part of the movie and the technique file would be very useful and appreciated.
Thanks in advance for your support.

I think you meant "way _too_ elegant and way _too_ easy..."

--
Matthew Miller
experientia docet

You're right. I wasn't proofreading two well. ;) Fixed.

-- Matt Petrowsky - ISO FileMaker Magazine Editor

If you have a scripted method to create a new window - you could title the window with "WindowTitle¶SomeIdentifier"
Filemaker allows returns in a window title but only ever shows the first line.

That could be handy storage space to identify a window.

cheers.

Nice tip Stephen! Thanks, yes, that would be very cool to simply use something like an incrementing window id value in the window name.

-- Matt Petrowsky - ISO FileMaker Magazine Editor

I stumbled on my own similar solution to the vexing sort-interface problem, but I think your custom functions that implement this solution are truly elegant, especially the control of the sorting icon arrows. I would never have thought of using the tab-stop formatting trick to utilize a single global variable to display information over multiple user interface elements. Inspiring!

Using tab stops to position the arrow is elegant, however I'm puzzled as to how or where the value of the tabs is set. I can't find any calls to the UISortIndicator ( field ; tabs). The data viewer shows it is changed/assigned after the sort records script step.

The tab value is set by the conditional formatting formula of the labels at the top of the sort columns (e.g. UISortIndicator ( StudentsLayout » People::nameFirst ; 1 ) for the "First" column and UISortIndicator ( StudentsLayout » People::nameLast ; 2 ) for the "Last" column). Crafty!

Sorry I didn't get to the original question right away. Busy these days. The whole goal is to keep as many of the "moving parts" tied to the elements they affect. So yes, the toggle is on the button on the column as a parameter and the indicator is on conditional formatting on the button element.

Then, in the script we have the direction function. Thanks for pointing it out tlander!

-- Matt Petrowsky - ISO FileMaker Magazine Editor

Any chance you could explain how to implement this function on a portal? I don't understand how this can work with a portal since the script uses the Sort-script step, that based on my experience can not be used on a portal? Is there a way to sort a portal using scripts ?

Bjørn Haugland

I don't think you can variably sort a portal. However do a search on 'Ultimate Portal Sorting" for 2 work around videos. JJ

JJ

I've been using this technique for years and found it's now temperamental in 15. Sometimes the indicators are correct, sometimes they don't update as you would expect. If the indicator is displayed on the 'Last' field and you click 'First' the indicator will remain on the 'Last' field. Clicking 'First' a second time will move the indicator to 'First' but it will be displaying the opposite indicator to how the records are sorted. Have you found a way to fix this?

This is off the top of my head because I've not looked at the file in a while but FileMaker has done a lot in the area of how/when a layout is rendered. You often need to use Refresh Object to forcibly get things to update.

This was done because Refresh Window was more expensive. I'd need to take a look at the file to see what needs to be done. It's also possible there are better/updated methods now.

-- Matt Petrowsky - ISO FileMaker Magazine Editor

This technique is quite old in that it was 2011. A much better approach with 15 would be to use a single segment Button Bar. This would allow you to include both the title of the header and the arrow. The arrow can be electively shown because the label on a button bar can be a calculation.

This is the method I would use in the current version.

-- Matt Petrowsky - ISO FileMaker Magazine Editor