top of page

Sort a list: The Best Way I've seen yet



Sorting. It's a core function of any database, and something users expect to be simple and intuitive. But implementing a truly elegant sorting system in FileMaker can be surprisingly tricky. How many ways have you seen to do this? They range from the simple and direct where the Sort step speficies the field and the order. That's the least brittle way – it survives renaming fields, tables, TOs, layouts, scripts, etc. Other ways I have seen are elegant, but maybe too clever for their own good.





Bt this way? This one? I like it. It's fast, clean, and incredibly user-friendly. And the best part? It's remarkably simple to implement, and portable between layouts, contexts, and database files.


Let me say up front that Chad Adams introduced this method to me, and I believe it started life with the brilliant team at Skeleton Key. I didn't think of this, but wish I had.


Under the Hood

The heart of this system is a single, concise script, "Simple Sort System." The core idea lies in its ability to infer the sort field from the current object context. By using the 'Go to Object' script step and then using the Sort script WITHOUT specifying a field, the script dynamically sorts as desired. This eliminates the need for separate scripts or complex conditional logic


Here's the script:



The layout setup involves two objects: A single-segment button bar (see my video on that) that serves as the header and the button to call the script, and sort icon(s). For these, I also used single-segment button bars, but they can be any type of graphic.


Each header button calls the "Simple Sort System" script, passing the object name of the corresponding field as a JSON parameter. For example, a button in the "Last Name" header would pass {"objectName":"person::last_name"}. The sort icons (up and down arrows) sit next to each header and use conditional visibility based on the current sort state of the field, which is stored in a global variable.


JSON Parameter to call the Sort Script



Paste in the script from the demo file below, and you're on your way. Check it out and let me know what you think! While you're at it, check out the custom theme in this file. There is some gooey goodness.



58 views0 comments

Recent Posts

See All

Comments


bottom of page