Sort lookup values in a picklist

  • 1
  • Question
  • Updated 4 years ago
  • Answered
I have a lookup reference field on Account that returns the looked up values from a custom object (Stage__c) in a picklist (which makes sense, as there are only 20 or so records in the looked up object). But I want the picklist entries to be in a sort order based on another field on Stage__c called Sort_Order__c. I can't find how to do that. Is there a magic way that I'm missing?
Photo of Glenn Elliott

Glenn Elliott, Champion

  • 7,738 Points 5k badge 2x thumb

Posted 5 years ago

  • 1
Photo of Zach McElrath

Zach McElrath, Employee

  • 49,056 Points 20k badge 2x thumb
1. Go create a "Stages" Model, and order it by Sort_Order__c.

2. Go to your field's "Advanced" properties, you'll see an "Option Source" property. If you set this to Model, rather than Automatic, then you get an "Option Model" property. Select your Stages model. Skuid will then use your Stages Model as its source of lookup/reference field entries, rather than the "Automatic" Model that Skuid auto-generates. And the records will be ordered by Sort Order.


Photo of Glenn Elliott

Glenn Elliott, Champion

  • 7,738 Points 5k badge 2x thumb
Thanks Zach. I knew it was something simple like that. :)
Photo of Barry Schnell

Barry Schnell, Champion

  • 18,076 Points 10k badge 2x thumb
Hey Zach -

Aside from using a separate model, is there any metadata property (e.g. field.options.???) that would force the SOQL generated for the lookup field to use a different order by clause other than Name?  

We have several of these situations on a page so we'd end up having to define several more models to accomplish when we really only need to specify the order by clause.  

Assuming we have to use a model for now, would be a welcome enhancement to be able to declaritively specify the order by clause on lookup fields.

Thanks!
Photo of Zach McElrath

Zach McElrath, Employee

  • 49,056 Points 20k badge 2x thumb
Via JavaScript, if you set field.options.order , this will be used instead of "Name" as the Order for the automatic source, e.g.

field.options.order = 'StageName, CloseDate DESC';


Photo of Zach McElrath

Zach McElrath, Employee

  • 49,056 Points 20k badge 2x thumb
For more info see the API Docs for the REFERENCE Field Renderer: http://help.skuidify.com/m/11720/l/214147-skuid-ui-field-renderers
Photo of Barry Schnell

Barry Schnell, Champion

  • 18,076 Points 10k badge 2x thumb
Thanks Zach.  This works well for us since we already have a custom renderer for most of these fields.  Would love to see sort order added to declaritive lookup filter options in a future release!

And Kudos to the team on the docs, awesome to see the improvements!!