How to sort options in a select field

Hey Everyone,

I have a select field with some options coming from a server connect data source and 2 static options. Wappler automatically places all static options on the top and then any data source options come below, what I would like to do is to place the static options at the bottom, however I am not sure how to do it.

Anybody came across this issue before? is there any work around to make this possible?

I haven’t had to place them at bottom before (I sometimes include a blank option with a -1 value which usually ensures it’s the default option selected)

I don’t know if you’re using the name and the value in your data, but if you’re not using the value, perhaps you could adjust that number so it’s higher that any value in the database source?

Just an idea.

I have tried this, but since I have values coming from a data source and static source they will not get sorted by value, maybe only the data source can be sorted directly from SQL but then the static source is still displayed at the bottom.

<select id="inp_Pat" class="form-control" name="PatId" dmx-on:changed="varNewPat.setValue(modalAddApp.serverconnectform1.inp_Pat.value)" dmx- bind:options="sc_patList.data.apiListPats.data" optiontext="FirstnameX+' '+LastnameX" optionvalue="Id">
     <optgroup label="______________"></optgroup>
     <option value="100">+ Add new pat</option>
    </select>

I’ll have a play around later today when I’m on the PC, unless someone answers before then or you figure it out :slight_smile:

Static values always get rendered before the dynamic.
Only way I see is you add the static values to your server action itself.
Use a custom query with union or some repeat and set value magic to add those at last.

I’d give each option a list order in the DB and sort by this value, adding your static options as the highest value for example. Easy way to achieve what you want and allows you to create, replace, and update, those otherwise static values… Is there any reason why they have to be static?