Sorted records on a related form

I have the following situation.

I have a form A using a parent table
I have a form B using a child table (1:n relation)

Form B is on a tabpanel and is dynamically put on the tabpanel using:

forms[_tab_form].elements.tabs.addTab(forms[_form], <other parameters>)

I want the records on Form B to be sorted and this sort is determined on runtime. So the initialSort in the form properties can not be used.
I’ve put in my onShow method a sort command:

forms[_form].controller.sort('someField asc');

This works, but only for the first record shown.
When I go to the next record in my foundset on form A, then the related data is shown, but not in the way I want it to be sorted.

Why doesn’t this work and how can I solve this (other then on change record on form A, resort all related forms on tabpanel)

I’ve seen that in 4.0 there is a initialSort field in the relation properties, but I have the problem in 3.5.7 and I don’t want this sort for all forms that use this relation.
So even the initialSort in relation properties is not a solution for me.

Why doesn’t the controller.sort() remain active?

It’s because the onShow event is triggered only when the form B is shown, if you then change form A current record that event is not triggered again.
You have two option:

  1. Use the onRecordSelection event on form A to trigger the related sort
  2. Use the onLoad event on form B to trigger the related sort

I’d go for option 1.

I agree, i am using option 1 and it works fine.

Regards,

I understand that the onShow is triggered once.

What I don’t understand is why I have to resort each time my form when my parent record changes.

Since I put controller.sort() on the child table, I expected that on change record A, records B are changed (because of the relation) and automatically put in the sort that I entered.
I expect that the controller.sort lives as long as the form lives. I expected that the controller.sort() would be similar as the initialSort of the form properties

ngervasi:

  1. Use the onRecordSelection event on form A to trigger the related sort

I’d go for option 1.

Are you sure this works? I tried it and I see that the sort() is not being done, because the related form is shown after the onRecordSelection trigger is finished :-(

It should… otherwise there’s always option 2 ;)

Hannibal Smith, A-Team:
I love it when a plan comes together!

:D

I succeeded, but not like I expected.
I did a sort on the child form and finally I found that I had to do a sort on the parentform relation:

		for (var i = 1; i <= forms[_tab_form].elements.tabs.getMaxTabIndex(); i++)
		{
			_relation_name = forms[_tab_form].elements.tabs.getTabRelationNameAt(i)
			_child_form = forms[_tab_form].elements.tabs.getTabFormNameAt(i)

			forms[_tab_form][_relation_name].sort('someField asc')
		}

in 4.0 you have an initial sort property on a relation so you can define what it should sort up front.