SmartObjects as Data Sources for Drop Downs

 

I’ve got a little project that requires specification of a month and a year on a SmartForm in order to populate a data table. The month and year must be in numeric format in order to act as inputs. I wanted the finished product to resemble this:

search

Along the way I learned a thing or two about using a SmartObject as a data source for a drop down list control on a SmartForm.

I started off with creating the drop down list control for the month selection by using static numeric values. This worked as far as input to the data table was concerned, but I want to display the names of the months instead of the numeric values.

Unfortunately, use of static values as a data source in a drop down list control does not allow you to control the display. It’s not like HTML, where you can assign option values inside a select tag:

standard-html-select1

Check out the configuration dialog — if you’re going with a static list, it’s, well, WYSIWYG:

configure-fixed-list-data-source

— Less than ideal.

So I decided to go the SmartObject route. That is, I created a new SmO just for the month data:

months-smo-1

Two columns — one has the ID, the other the name. I entered the months in order so the ID could double as the ordinal (which is what we need to send to our list).

The data source configuration reflects the change —

configure-months-smo-data-source

The result is almost magical. I get my value as the ID, and I get my month name displayed. The control passes the ID to the list as it should. The only rub is:

ddl-monthname-unsorted

 As you can see, the list is sorted alphabetically by month name. I’d prefer the months displayed by ordinal — which, for this SmO, is the ID.

So I created another SmO for the month data. The structure is identical to the former, except for the addition of a numeric column called Ordinal:

months-smo-2

Now to change the data source for my drop down list:

configure-months-smo-2-data-source

There is a very subtle difference in the configuration between the two SmO’s that makes all the difference: the value of “value” is now the Ordinal column instead of the ID column.

Here’s that difference:

ddl-monthname-sorted

Our month drop down list is now sorted by ordinal!

SmartObjects as Data Sources for Drop Downs