FileMaker® Pro Tip-n-Trick: Smart & Simple Column Sort
By: RJ Carroll
One of the most-requested features from FileMaker Pro developers is a one-click simple column sort. Trying to sort out how to sort can be a tricky business. The typical way to implement column sort from list-view is by using buttons above each column. First, the user calls a script by clicking on a field name in the column header. Usually, the script includes a number of hard-coded “Sort Records” steps. Then, the script decides which field to sort and how from a series of If/Else If steps. Each order of each potential field would require its own script step.) Scripts like this leave a lot of things to change if you add or delete fields. (They also leave a lot of code to maintain in general.) Before FileMaker introduced “Sort Records by Field”, this was basically the only sort of way to do it (pardon the pun).
Sort Records by Field
A simpler approach is to leverage the power of “Sort Records by Field.” One advantage of “Sort Records by Field” is that, unlike “Sort Records,” you can leave the field unspecified and use the context of the currently active field. It also eliminates the need for extensive “If…Else” branching logic and hard-coded sort orders in the sorting script. The only issue with using “Sort Records by Field” this way is that when a user clicks a button on the layout, the user isn’t actually in the field when the script gets called. Most users would expect to click a button (such as the field’s name) in the column header to call a sort script, but since clicking a button takes you out of the field, it won’t work. So what do you do?
From Button to Trigger
One clever workaround: place copies of the fields you want for sorting in the header and use an OnObjectEnter trigger to invoke the script. This eliminates all need for script parameters and branching logic altogether. It also allows for powerful one-click column sorting. Just style those fields to look like “sort buttons”. Now have an elegant method for sorting by columns that is simple and easy. It is also manageable, easy to maintain as your solution changes. Check out this implementation by downloading our demo file. I think you’ll find it’s remarkably simple with this technique to get all your sorting quickly sorted out.
Download the demo file and give it a sort!
*This FileMaker how-to article is provided for free and as-is, use, enjoy, learn, and experiment at your own risk – but have fun! Excelisys does not offer any free support or free assistance with any of the contents of this blog post. If you would like help or assistance, please consider retaining Excelisys’ consulting & development services.
About Excelisys, Inc.: Founded in 2001, Excelisys (www.excelisys.com) is an FBA Platinum Partner and FileMaker Certified developer organization. Excelisys specializes in designing, developing, customizing, supporting, consulting, migrating, upgrading, fixing, and integrating of database solutions for Desktop, Mobile, and Web. Our core technology competencies are FileMaker Pro, FileMaker Go, PostgreSQL, and MySQL for database frameworks. Complimenting those database frameworks we have competency with WordPress, PHP, CodeIgniter, Joomla, Drupal, Magento, CSS, HTML5, and Javascript for web sites and web applications.
Aside from providing excellent customer service, our goals are to use these technologies to intuitively automate your organization’s data solution needs seamlessly and flawlessly across the web, mobile, and desktop platforms. Contact Excelisys today for a free estimate and consultation regarding your business software automation needs @ 866-592-9235.
Excelisys, Inc. is an independent entity and this web site/information/blog post has not been authorized, sponsored, or otherwise affiliated with FileMaker, Inc. FileMaker is a trademark of FileMaker, Inc., registered in the U.S. and other countries.
very clever and useful,
thanks
Thanks Yann, glad you found it useful!
Great technique. I have often thought how to make the sort script more portable. I came a long way except for the final part where the sort step itself still needed a tedious programming step. Just tested yours and will be implementing this in my solution for sure. Thanks a lot, I will be adding your name to the credits line.
Thanks Peter! RJ will be flattered.
Nice! Thanks for sharing. This is a very elegant solution to ‘direct’ sorting. Am I wrong to think that sorting in a portal still requires a kludge? I guess I’ll need to investigate the ‘sort by field’ script step…
Thanks, John. Glad you appreciate the ‘elegance’ of it! So, with portal filtering, you’re right that it’s not quite so elegant, but it is possible to apply a similar technique with just a little more overhead:
1. Keep the styled fields with the OnObjectEnter step and place them in the portal header.
2. Instead of calling a script which uses “Sort Field by Name,” call a script which (a) sets a global variable to Get ( ActiveFieldName ) and (b) refreshes the target portal. (You could even use the same script with a parameter for whether you’re sorting a found set or a portal).
3. Sort the portal by an unstored calculation in the target table which evaluates GetField ( $$FieldName ).
That’s going to be a little slower, and requires a bit more overhead, but it’s not quite a kludge in the sense of adding lots of branching in your script.
-RJ
[…] Source: Excelisys FileMaker Pro Tip-n-Trick: Simple Column Sort | Excelisys […]
I looked at this file a few times before and often wondered what was different from normal sorting methods. Didn’t spend more than a few seconds clicking icons.
The comment by Yann Liqueur-Salzédo caught my eye and I was encouraged to look a bit closer. Eventually I got it!!
Wow – that is such a clever idea! I love it!
Thank you Robert! Glad your epiphany came through! Appreciate the feedback – share with friends! 🙂