We had to do something like this when trying to order item lines on a packing slip page. What we ened up doing was create a custom transaction line field and put a formula as the default value that would evaluate to the order we wanted to see, and then get fremarker to order the list by that field.