RefreshTable action 1:n sorting problem 

RefreshTable action 1:n sorting problem 

  

Hi,

I have a screen with an 1:n (Kantoor:Adviseurs) relation with two TableRecords elements. On clicking a Kantoor a Table with Adviseurs is refreshed (with a filter). So far so good. However on sorting an Adviseur name it looks like the filter is not giving the correct result (a record from another Kantoor is shown). 


Regards, Harry

I tried a couple of things to get this right, but alas.... Is this a bug or am I missing something?

Regards, Harry

Hi Harry,

So, when you click in a K, your code refresh the A table to show A records associated to this specific K record. This is working.

But if you sort the A records by name, you are getting a change in K table, that is not showing anymore what is supposed to show.

For me, the most probable cause is that you are calling an action, the refresh, that is also refreshing the K table and its source.

You shouldn't do this, as the relationship is in the other way. So, be sure that when you sort A table, it does not refresh K source and table.

Without seeing the code, I can't think of anything else.

Cheers

Eduardo Jauch

Hi Eduardo,

Yes I thought of that too, but since the refresh only refreshes the child entity that seems not the case. I think is has something to do with the childentity not knowing what is the current record in the parent entity (on sorting always the last record in the child entity is shown). But that seems strange because it uses the same action for clicking in the table of the parent entity and that works. Maybe I'm overlooking something completely, but I can't figur it out. 

I have attached a test OML with companies employees to show this. I tested it with Comp A, Comp B, Comp C and EmpA1, EmpA2, EmpB1, EmpB2, EmpC1. To show the Emps you click on the Company in the Company table. If you sort the Emp table it always show EmpC1.

Regards, Harry

Solution

Hi Harry,

This is the normal behavior.
You have two tables, the second depends on which row is selected in the first.

When you enter the screen for the first time, it shows you the companies and none employee, because you didn't selected any company yet.

This happens because at the time the Preparation run, the table in the screen wasn't rendered yet, so the "current" of that table list is empty. Than, the aggregate is executed and no employees are found because there is no valid company selected.

If, when the page is rendered, you click in a company, everything will work as a charm, including the employees table, and after this, if you sort this table, it will be sorting the elements it has.

BUT...

If, as soon as you enter, you click in the sorting of the "Employee name", it will refresh the aggregate that gives the source to the table, using the current of the Company table list. Now, as the company was already rendered, it will have a valid company, because when a table render its elements, at the end of the rendering, the current is set to the last element in the list.

Than you see the employees for the last company visible in the table, even if you didn't clicked in anything.

A simple way to avoid this is to use an IF around the second table with the condition set to TRUE only in case the table list is not Empty. This way, at first, the table will not even be shown, but only when the user explicitly click in a table. In this case, in the refresh, you should ajax refresh the IF (given a name to it), otherwise it will not change and will always be invisible.

Another way to do this is to in the click action in the first table, use the List.Current to set the ID in a LOCAL variable, and use this local variable in the aggregate filter. This way, the second table will show results only after you click in the first. The sort without clicking in the first will not show results, as the local will be NullIdentifier() in the beginning.

Hope this helps. :)

Cheers,
Eduardo Jauch


Solution

I've used the second way to you to see:

https://eduardojauch.outsystemscloud.com/TestHarry/CompaniesWithEmployees.aspx?(Not.Licensed.For.Production)=

The oml with the changes is attached.

Cheers,
Eduardo Jauch

Eduardo,

Thank you very much for the thorough explanition and the OML. It's all clear to me now.

Regards, Harry