Diese Seite mit anderen teilen ...

Informationen zum Thema:
Forum:
WinDev Forum
Beiträge im Thema:
11
Erster Beitrag:
vor 4 Jahren, 4 Monaten
Letzter Beitrag:
vor 4 Jahren, 4 Monaten
Beteiligte Autoren:
Adrian A., DerekT, Allard, Jose Antonio Garrido, Arie

[WD 18] combobox/column table sorting

Startbeitrag von Adrian A. am 16.04.2014 13:50

Hi,

For a combobox column type of a table is there a way the table can sort the column by its displayed value and not by stored item ?

Thanks,
Adrian

Antworten:

Hi,

If you fill it with a query then you can add a sort in the query. This shoul also order the combo table

regards

Allard

von Allard - am 17.04.2014 09:56
Hi Allard,

Thank you for your answer but I want to sort the column of a table built with combo box control values, not sorting the list of combo box itself.
It seems table still sorts on the underlying index value not displayed value.

Adrian

von Adrian A. - am 18.04.2014 08:00
Adrian

Define a structure containing the content type required for the combo
Declare an array as an array of your structure
Use a query to to fetch the data fill an array using the columns of the structure.
OR use FileToArray() if this suits you better.
The array will be filled according to the query 'order by' or you sort the array on the required column

Populate the combo (standard control not table) using the array - 'by variable' option.
Initialise the combo using ListDisplay() when the query is run.
All fields described in the structure will then be available in the combo for selection/display using the 'combo.fieldname' syntax.

To change the sort order programmatically just sort the array as required and refresh the combo with ListDisplay()

May sound like more work but I have found it more flexible table type combos and tables alike.

von DerekT - am 18.04.2014 17:31
Hi

You can do a table sort with tablesort() a well read thehelp on this fuction


regards

Allard

von Allard - am 19.04.2014 16:58
Allard
I believe Adrian is using a 'Table' combo.
TableSort() will throw an error as the compiler sees this as a combo and is expecting ListSort().
Unfortunately ListSort() cannot be used to specify a column in a 'Table' combo.

von DerekT - am 20.04.2014 11:08
Hi

Thanks all for suggestions, I am sorry not being more explicit. The questions is about a table control linked to a file, one of its column being of type combo box and linked to a second file (files in a relation one to many). Now when clicking on column headers, the table sorts correctly all columns except the "combo box" where the column is still sorted by its stored item key and not by displayed item. ListSort() has no effect and I can not build on the fly the content of combo box without breaking the relation of files keys.

Regards,
Adrian

von Adrian A. - am 23.04.2014 08:54
Adrian,

it looks like WD does not support sorting on a combo-column? I don't know.
Maybe you can add an extra (invisible) column, type text and filled with the actual text. Which could come from a the query as well.
Then try to catch the sort-click of the user and use TableSort to sort on this hidden column, instead of the combo-column.

von Arie - am 23.04.2014 09:08
Hi Arie,

Yes it works, I created a new column (default text), then in event "Displaying a row of Table" I copied the displayed value to the new column:
COL_NEW= COL_COMBO..DisplayedValue.
The new column now sorts properly while the old combo I set it invisible.
Great!

Thanks all.
Adrian

Note: The table should be in "loaded in memory" mode.

von Adrian A. - am 23.04.2014 09:48
Also, If you want the table to be editable, the configuration is a bit different.

Make the Combo_Box column visible, and the new calculated column invisible.

The code on the Row Display Event is the same you already have:
COL_NEW = COL_COMBO..DisplayedValue.

And add this code In the event "Whenever Sorting" Event of column Combo Box

tablesort(TABLE_Name,COL_NEW)

For me it works perfectly.

Regards,
José Antonio.

von Jose Antonio Garrido - am 24.04.2014 08:43
Hi Jose,

Yes, if the column is visible then it can be used in edit mode. The selected sort order can be maintained in same "Whenever Sorting" event, something like this (supposing the user do not use multiple column sorting, if the case, code needs to be extended):


LstColumns is string
ColName is string = COL_NEW..Name

LstColumns = TableSortedColumn(TABLE_Name)

IF LstColumns="" THEN
TableSort(TABLE_Name,ColName)
RETURN
END

FOR EACH STRING substring OF LstColumns SEPARATED BY TAB
IF substring = ColName THEN
TableSort(TABLE_Name,"-" + ColName)
ELSE
TableSort(TABLE_Name,ColName)
END
END


however consistency of UI is not quite right, the sort symbol does not get shown in column header, also the filter action didn't get an event like "Whenever Filtering".

Thanks for suggestion.
Regards,
Adrian

von Adrian A. - am 24.04.2014 10:27
Zur Information:
MySnip.de hat keinen Einfluss auf die Inhalte der Beiträge. Bitte kontaktieren Sie den Administrator des Forums bei Problemen oder Löschforderungen über die Kontaktseite.
Falls die Kontaktaufnahme mit dem Administrator des Forums fehlschlägt, kontaktieren Sie uns bitte über die in unserem Impressum angegebenen Daten.