Default sorting of table widget

Hello

I have a table widget with let’s say 4 columns, all with numbers in it.

The user wants to have the table sorted by column 1, from highest value to lowest.

At the moment he has to do that by pressing the sorting button from the table everytime he opens the page.

Is it somehow possible to define like a default sorting order of the table? So when the page is opened it is directly sorted the correct way? Or is the only possibility for this to sort the entries inside the data table in the application?

thanks

Hi @Stefan_Ruttimann

For Table widget I don’t think it’s possible because there is no sortConfiguration property like there is on AlarmList for example, if you want the data to be preorder, you have to order the data on the PLC side to be sure that the data will be ordered as the user want.

Regards,
Florent

Hi Stefan,

if it helps, and if you’re working with independent arrays for each column, I can provide a sorting algorithm I wrote for the same use case. It sorts the table in ascending order by StationID while keeping the corresponding values in the other arrays aligned.

IF SortLimit > 1 THEN
    REPEAT
        Swapped := FALSE;

        FOR i := 1 TO SortLimit - 1 DO
            IF Table.StationID[i] > Table.StationID[i + 1] THEN

                // Swap StationID
                TempStationID := Table.StationID[i];
                Table.StationID[i] := Table.StationID[i + 1];
                Table.StationID[i + 1] := TempStationID;

                // Swap corresponding Counter
                TempCounter := Table.Counter[i];
                Table.Counter[i] := Table.Counter[i + 1];
                Table.Counter[i + 1] := TempCounter;

                Swapped := TRUE;
            END_IF
        END_FOR

        SortLimit := SortLimit - 1;

    UNTIL NOT Swapped OR SortLimit <= 1
    END_REPEAT
END_IF

This is essentially an optimized bubble sort and worked well for my application.

@simon.steiger Thanks for your code example.

I just find it very unfortunate that this is not possible directly in mappView, especially since the visualization apparently supports this functionality, but unfortunately only after a user interaction. I don’t understand why this can’t be done via an event action, for example.

Hi Stefan,

I’ve quickly check the Table widget code and internally there is the order internally, just by default no sorting order to begin, I think it not finished, also ordering is only allow on vertical table.

I can check on that to add a new widget to the GitHub - br-automation-community/mappView-CustomWidgets: Collection of new and modified mappView widgets · GitHub repo, a Table widget with order property.

Regards,
Florent