Alphabetize or Sort Navigation Menus

December 1, 2008

The other day I was staring at the Administration menu trying to find the ‘Admin Server’ menu item. I am embarrassed to admit that the lack of alphabetical ordering in the menu list causes me to spend a lot of time spacing out starting at the Administration menu looking for the Admin Server menu item. Way too much time, unfortunately.

I have tired of this act for the last time, so I set out take a crack at creating a component that would reorganize the menus in alphabetical order. Originally, I was most interested in the Administration menu, but in the end the code just as easily allows for all the menus (those created by navBuilder) to be sorted.

This was the most unobtrusive way I could figure out to do this, and it seems to perform quickly enough on my machine (famous last words), but I could certainly imagine there are faster ways to accomplish this. I suppose there could be some kind of sort on insert of the menus, etc., but again, this was the fastest time to market effort I could come up with that works without a noticeable rendering deficiency.

The short discussion of how this gets done starts with an override and super include of ‘custom_finish_layout_init’. Then we set the load order to something really high so that our code takes effect after everything else. I did not do this the first time and the menu for configuration migration utility kept getting added in after the sort.

After that we need a function that takes a menu id and performs the sorting. So, the first problem really is not the sorting, it is the fact that this include takes place within a JavaScript function. This means we cannot just declare a function. To get around this I create JSON Object and give IT a function. Then we use this object to make our sort calls.

Anyway, I hope there were some interesting things in here and you might find this useful.

© 2020 Jason Stortz (version 20200607-210013)