Perspective dropdown How to Default to the First Value?

I have some dropdowns with their options bound to a dataset. When the dataset updates the dropdowns are left showing the "Select..." text. Is there a way to have them default to an option in the dataset?

I did find some posts using selectedValue property but I guess that is for the View dropdown and isn't it read only?

event.source.parent.getComponent('Dropdown 1').selectedValue = 0

Try this:

  • Create custom.dd1options on the dropdown. Bind that to the dataset source.
  • Bind the dropdown options to custom.dd1options. The dropdown options will automatically update any time the dataset changes.
  • Put an expression binding on the dropdown value property. Configure the expression as shown below.
    Dropdown default

The expression will be executed any time the dataset changes on custom.dd1options. The transform will return the value of option 0.
`

I don't think you need the expression transform. Just the expression binding:

{this.custom.options}[0]["value"]
2 Likes

You are correct!

Wouldn't that binding stop you from selecting something other than the first option? I figure you'd need a property change script on the data binding, then set the selected value to the first result when it changes.

My understanding is that the binding only executes when custom.dd1options changes. The user is free to choose any option in the meantime.

After making the changes it's showing the updated dataset like before but is still showing "Select..." text after the dataset is changed.

image
image

image
image

When adding the value expression binding there is a error.
image

image
image

Nice well-cropped screen grabs!

  • The first binding looks correct. The custom.dd5option is bound correctly and you have a 2 x 2 dataset.
  • The second binding looks correct. It should be returning a copy of the previous dataset.
  • I think the last binding be
    {this.custom.dd5options}[0]["value"]
    You need to point it to the custom prop as the Dropdown_lineup.props.options binding.
1 Like

That would make sense. Now I get a conversion error and the report that is using the pulldown is looping.
image

{this.custom.dd5option}[0]["value"]
image

What does it say if you hover over the red error text?

image

But at this point you don't want array or dataset.

Actually it wants just that, or I doubt that it would tell you other wise.

What happens if you change the expression binding to this:

{this.custom.dd5option}[0]

The Options should have and is a dataset but the value should just be a value. ???

No error after removing the "["value"]" from the end but the dropdown can not be set to anything and is now always blank and the report is looping or updating over and over.

When I click on it, it has the correct dataset or options but whatever is selected it just goes blank again.
image

Some important points here:

  1. If your Dropdown is configured to be multi-select, value will expect an array or list.
  2. You might consider use of a change script on the custom property instead, which writes the 0th value to the value prop.
2 Likes

{this.custom.dd5option}[0, 'value']

The option multiSelect is false.

One issue was the expression tags updating the datasets was running fixed rate. I changed then to event driven and it's no longer looping but it seems the last step to update the dropdowns selection is not happening.

Just seeing the post from @pascal.fragnoud and it seems to work now with the Dropdown_Lineup.props.value expression binding.

Not sure what the working code would be for the change script would be.

Something like

self.props.value = currentValue.value[0].value

use the property browser to make sure the paths are correct.

The dropdown value expression binding worked well until today. For some reason it now updates every second even though nothing has changed, so the report just keeps loading over and over. I was working on an unrelated button on the Perspective screen and the report just started loading.

The other day I had to change the memory tag expression that creates the dataset for the dropdown from fixed rate execution mode to event and the fixed the looping until today.

I don't know how it was working before. I even did a gateway restore from yesterday and the reports still loop. ???

Looking at the memory tags expression, there is a poll rate argument in the runScript function and it was set to 1 second. It seems it's not decided that this is a change and is updating the report even thought the values passed to the report unchanged. What the?