Forums

Sorting a dynamic dropdown

redowl 09 Sep, 2012
Hi,

i have a dynamic dropdown (users) the value key is id and the text key is name.
This results in a drop down list that is sorted on id and not on name, is there any way i can add some sort of "order by" or do i have to set the value key to name?
GreyHead 10 Sep, 2012
Hi redowl,

Please try the Order Fields box on the Data Displayer tab of the DB Multi Record Loader action. I think that may work OK.

Bob
GreyHead 13 Nov, 2012
Hi redowl,

I did some more checking for another post this morning and this doesn't work for the initial query. I have developed a workaround using some Custom Code. Please see this FAQ.

Bob
rogeranton 23 Nov, 2012
Hi GreyHead
I got the same issue with a dynamic drop-down from a database table. When I try your solution a table with a sortable clumn is shown above the drop-down (I don't want that), and the drop-down is still not sorted (it's sorted by cf_id).
GreyHead 23 Nov, 2012
Hi rogeranton,

Which solution did you try? The one in the FAQ should be OK?

Bob
rogeranton 17 Apr, 2013
Hi

I've tried the FAQ solution. I just don't get it to work.

The dynamic drop-down works fine , but I'm not able to change the default sorting.
The On Load event holds only three actions:

Show HTML
Custom Code
DB Multi Record Loader

I've copied the first code from the FAQ to the Custom Code action and changed the highlighted 'id' to 'firmanavn'. Is that really the only thing I have to do?

Roger
GreyHead 17 Apr, 2013
Hi Roger,

I think that the Custom Code needs to be after the DB Multi-Record Loader, otherwise there is no data to sort. And I'd probably put the Show HTML action last to be tidy.

Bob
rogeranton 17 Apr, 2013
The changes didn't make any difference. Would you care to take a look at my form? The site is not in production so it's ok if you mess it up :wink:

The drop-down appears to be alphabetically because it is entered alphabetically in the table, but the last entry starts with A and shows up at the bottom. The form name is SSV_arsmote.

I'll send you login info in a PM if it's ok.

Roger
GreyHead 17 Apr, 2013
Hi roger,

By all means email or PM me the site URL, the name of the form, and a SuperAdmin login and I'll take a quick look.

Bob
GreyHead 17 Apr, 2013
Hi Roger,

It's fixed I think. I added this to the WHERE box in the DB Multi Record Loader action
1 ORDER BY `firmanavn`


The Custom code I suggested didn't work though.

Bob
rogeranton 23 Apr, 2013
Thank's a lot Bob. This works just as I want it.

Roger
GreyHead 23 Apr, 2013
Hi Roger,

Thanks :-)

For other readers: This creates a MySQL WHERE clause like WHERE 1 ORDER BY `column_name` and because '1' is always true in MySQL that part does nothing leaving just the ORDER BY clause. The '1' is needed because otherwise the clause would be WHERE ORDER BY . . . which is not valid.

Bob
This topic is locked and no more replies can be posted.