I had wanted to implement an ability to reorder them dynamically with this mod, but there were some things preventing that.
See this request from when I first wrote the mod
https://forums.factorio.com/viewtopic.php?f=28&t=79583
I can explain some technical details in case anyone familiar with factorio modding has some good ideas to work around these constraints.
The hope was that if I could set an ordering property of the GUI elements then I would easily be able to achieve the desired behavior. For example group A could be the first elements, then group B, etc
This would be the easiest way to implement the reorder, but it would require WUBE to do some back end work to enable, and it may be a heavy lift and not be worth it.
They use this same order string logic when the game is loading up to sort out the crafting recipes and various other things, but I don't think they have anything that supports dynamically reordering in during runtime.
For example, recipes have an order string associated with them but it is read-only while the game is running, so it can't be updated by mods.
https://lua-api.factorio.com/latest/LuaRecipe.html#LuaRecipe.order
Similarly, the interface to get the parent of an element, i.e., at the top level if it is 'top' or 'left' is read-only, so you can't just overwrite button A's parent to be 'left'.
https://lua-api.factorio.com/latest/LuaGuiElement.html#LuaGuiElement.parent
The GUI children are also read-only:
https://lua-api.factorio.com/latest/LuaGuiElement.html#LuaGuiElement.children
It may be possible to brute force 'clone' the elements and delete the original, but that could potentially mess a few things up.
The game tracks which mod creates the GUI and this would then make this mod the owner of all the cloned elements. An even more likely thing to cause issues is that mods that add GUIs may expect their GUI to be in the top GUI at all times and break the other mods functionality.