first of the sort, for me this works:
function onLoad(event) {
controller.sort("orderid desc",true);
}
But only if you then show the main/shared foundset in it that then will be loaded.
But if that form is used to load an existing foundset (like a relation) after it is loaded, the sort that you do there is not applied to that foundset.
because above is the same as this:
function onLoad(event) {
foundset.sort("orderid desc",true);
}
If you would make a simple form on orders and show that as main with one of the 2 onload methods above, you will see that it will sort.
But if you would use that form in a tabpanel where you show a related set of order data (company → orders) then the foundset your are accessing there
is not yet the related foundset, because the form UI is just loaded , And then used to show the related foundset (which is already loaded long before that)
If you are really showing a related foundset in that that you want to sort, it is way better that you tell that to the relation itself (initial sort)
Because that is one query less (not just first load it and then sort it again)
by the way if you say sort in the onload that would be the same then setting initialSort property on the form itself.
To make this a bit more clear in an example. Let say you do this yourself in code:
forms.myform.loadRecords(foundsetX);
if that myform has your onload method then this is what happens, if this piece of code is evaluated:
“forms.myform”
then onload is already called, because you access the form and it is loaded.
the after that you do
.loadRecords(foundsetX);
on it and then the foundset is loaded.
So this is also how Servoy works internally for example in tabpanels that show related records.
now about
“NOTE: the onLoad event bubbles up, meaning that the onLoad event of a form displayed in a tabPanel is fired before the onLoad event of the parent.”
wiki is wrong here, because it is just the other way around, onLoad/onShow events bubble down so the go from parent to child (mainform to tab in tabpanel to tab in that tabs tabpanel)