Select2 - multiple select - options order
Select2 - multiple select - options order
vladimirijus
Posts: 16Questions: 4Answers: 1
in Editor
How to record select2 options into db ordered by user choice, not by id?
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
How are you getting the values? Select2 is probably just showing them in the order they are added, so you need to get the data from the server in the required order. If you are using the PHP or .NET libraries the
Field->options()
method will use the label value automatically. If you want to use some other order you would use a custom method.Allan
Hi Allan,
Thank you for your help. You can find example here: http://backend.front.rs/list.php
I'm getting values using Mjoin:
and also, I use this to stop Select2 making alphabetical reorder on option select:
What I need is an option to record values one-to-many in database in order user entered (for example region 5, region 3, region 6...)
Vladimir
I'm not sure that there is a way to retain the original order with the Editor PHP API. The
Mjoin
doesn't offer an order by option at this time.If it were to, then to retain the original ordering what I think you would need to do is add an auto incrementing sequence to the database. So as each new item is added - and Editor will add it in the order submitted - it gets a sequential identifier. Then when you read them back from the database the order by clause would be set to match.
I'll take a look at adding that for the next version of Editor as I can see that might be quite useful.
Allan
Table
top_banners_regions
which holds particular options, already has auto incrementing sequence (id). Should I add something to the Mjoin?It would be great if you add this feature to Editor, because data ordering is quite important to users.
Just to confirm - this will be in the next version of Editor.
Mjoin
will have anorder()
method which you can use to specify which property of the joined table should be used to order the data.Regards,
Allan
I've sent you an e-mail with the update :-)
Great, thank you!
Hi,
I search this method too !
Can you send me this update, Allan ?
Thanks a lot !
Gaétan
Editor 1.5.6 will be out next week if you can hang on a little bit longer. There are a couple of other related changes that I'd like to make first.
Allan
Yes, I can.
thanks Allan !