controller.sort not working?

Hi Folks

Using ‘forms.fabman_frm_insp_table.controller.sort(‘fi_id desc’)’ in the onLoad of a table form - the sort is not working. Tried this on multiple forms now. Similar result in setting the initialSort in form properties - no sorting done1.

What did I miss?

EDIT: For others - seems the sort need to be in the onShow and does not work in the onLoad - perhaps the wiki could be updated to clarify that?

In the onLoad, the foundset is not really there!! you have to do that in the onShow and use the first argument (is true when onShow is fired for the first time)

the onLoad is only used for gui, element stuff…

Harjo:
In the onLoad, the foundset is not really there!! you have to do that in the onShow and use the first argument (is true when onShow is fired for the first time)

the onLoad is only used for gui, element stuff…

Thanks for the explanation Harjo.

It’s even in the Wiki :

onLoad

The method that is triggered when a form is loaded/reloaded from the repository; used to alter elements, set globals, hide toolbars, etc; onShow method can also be assigned.
NOTE: onShow should be used to access current foundset dataproviders; onLoad cannot be used because the foundset data is not loaded until after the form is loaded.
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.

lwjwillemsen:
It’s even in the Wiki :

onLoad

The method that is triggered when a form is loaded/reloaded from the repository; used to alter elements, set globals, hide toolbars, etc; onShow method can also be assigned.
NOTE: onShow should be used to access current foundset dataproviders; onLoad cannot be used because the foundset data is not loaded until after the form is loaded.
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.

Nice one but that doesn’t help when you search the ‘sort’. T hats where the comment that it needs to be in the onShow should be - is’nt it???

Hi all.

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.

Anyone can explain me it on detail. I think I don’t understand it :oops:
Best regards. Roberto.

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)

Brilliant response - thanks Johan.

Perfect!!! jcompagner

Thanks for four answer. :P