PC SOFT

FORUMS PROFESSIONNELS
WINDEVWEBDEV et WINDEV Mobile

Accueil → WINDEV 2024 → [WD 18] combobox/column table sorting
[WD 18] combobox/column table sorting
Débuté par Adrian A., 16 avr. 2014 15:50 - 12 réponses
Posté le 16 avril 2014 - 15: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
Posté le 17 avril 2014 - 11:56
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
Posté le 18 avril 2014 - 10:00
Hi Allard,

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

Adrian
Posté le 18 avril 2014 - 19:31
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.
Posté le 19 avril 2014 - 18:58
Hi

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


regards

Allard
Membre enregistré
68 messages
Posté le 19 avril 2014 - 19:19
Try this -

Create a new column in your table - "COL_ComboVal", and mark it not visible.
In the display row code for the table, set COL_ComboVal equal to the ..displayedvalue of the combo control

when the table is displayed, use tablesort(thetable, "COL_ComboVal")

I'm not sure of how you reference the combo control in the table cell. There was a webinar the other day on WxLive on Combobox rows, but I missed it. <g>

JAT,
Chris

--
Sometimes waiting is the best way forward...
Posté le 20 avril 2014 - 13:08
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.
Posté le 23 avril 2014 - 10:54
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
Posté le 23 avril 2014 - 11:08
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.
Posté le 23 avril 2014 - 11:48
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
Posté le 23 avril 2014 - 13:07
ccordes wrote:
Try this -

Create a new column in your table - "COL_ComboVal", and mark it not visible.
In the display row code for the table, set COL_ComboVal equal to the ..displayedvalue of the combo control

when the table is displayed, use tablesort(thetable, "COL_ComboVal")

I'm not sure of how you reference the combo control in the table cell. There was a webinar the other day on WxLive on Combobox rows, but I missed it. <g>

JAT,
Chris

--
Sometimes waiting is the best way forward...


Hi ccordes,

I did not see your post because I was editing on mysnip and your post did not get there.
It seems you already post a good solution the same conclusion I get after reading Arie suggestions.
For a read only column this is all I need (sorting and filtering of combobox column).

Thank you,
Adrian
Posté le 24 avril 2014 - 10:43
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.
Posté le 24 avril 2014 - 12:27
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"...

Regards,
Adrian