Hierarchical Portal Filtering Incorporating Drag-n-Drop Technique
This is part three of a three-part series on hierarchical portal filtering in FileMaker Pro. You can find part one here and part two here. Demonstrating how to provide drag-and-drop rearranging and arbitrary sorting of hierarchical items.
By Andy Persons
A common request when implementing hierarchical portal filtering is the ability to drag an item exactly where you want it to go. If you want it inside another element, just drag it on top. If you want it between two elements, just drag it in between them.
It’s a standard interface element in other areas, such as the Finder in MacOS, Explorer in Windows, and on some websites. However, the intuitive simplicity conceals quite a bit of complexity.
- It needs to be able to clearly indicate when an item will be dropped “inside” another and when it will be “inserted” between two items.
- It needs to elegantly handle the edge case when a user drags an item between the last child of parent and the parent’s “sibling”. Does it become the last child of that parent or the next sibling of the parent?
- It needs to maintain the hierarchical structure at all times while providing arbitrary sort order.
Here’s the overview:
- This technique uses the drag-and-drop method demonstrated in this file, along with drop-target CSS to provide the visual indicators.
- Each portal row has three container fields as drop targets. The top field will sort the dragged item above it (indicated by a line on its top border) and the bottom one will sort it below it (indicated by a line on its bottom border). The third field will make the dragged item a child of that record. Its drop target CSS is set to change the entire background color.
- Sorting is accomplished by loading a dictionary of each related record’s id and sort number into a global variable at record load. The sort_path field uses this to calculate the sort number of each ancestor record into a single decimal number. To maintain the correct hierarchical sorting, the sort is padded with zeroes at the beginning and end. If the limits of four integer and six decimal digits are exceeded, it will automatically re-serialize the siblings.
These features could also be combined with the sorting from Part 2, if desired.
**This 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’ FileMaker Pro consulting & development services.
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.