Dataset Filtering on Dropdowns

I am using a memory tag data set to reference options in a dropdown on my perspective app. I want to have a second dropdown that references all options that have the same attribute based on the first dropdowns selection.

Example: Dataset -

Colorado, Denver
Colorado, Grand Junction
Nevada, Las Vegas
California, L.A.
Virginia, Lexington

If in the first dropdown selection I choose “Colorado”, I want the second dropdown to display options “Denver” and “Grand Junction”.

I currently have this code in the second dropdown:

tabList = []
for row in range(value.getRowCount()):
	tabList.append(self.getSibling("Zone_Select_Drop").props.value)
return tabList

You need to actually loop through the data set. This code will add the same value for however many rows are in the value dataset.

Something more like

tabList = []

selectedValue = self.getSibling("Zone_Select_Drop").props.value

for row in range(value.getRowCount()):
    if value.getValueAt(row, 0) == selectedValue:
        tabList.append(value.getValueAt(row, 1)

return tabList

That of course can be compressed to a comprehension, but it should get you close.

Why am I getting an Error on the return?
image

tooltip saying “no viable alternative at input ‘return’”

Check your indentation. It needs to all be either tabs or spaces, and it needs to be at the correct level.

I can see from the screen shot that it looks incorrect. Copy and paste can often mess around with it.

De-dent lines 14 and 15 one step each.

Nailed it. Thanks guys!

14 posts were split to a new topic: Help with data entry form

I have case like you need for filter second dropdown based on selection of first dropdown, can you share full script?

Well... Can you share the full question ?

I am using Query to reference option in a dropdown. Same like -Casey_Roman , I want to have a second dropdown based on the first dropdowns selection:

Detail Table:
ID | Area | Process Name
1 | Area 1 | Process 1
2 | Area 1 | Process 2
3 | Area 1 | Process 3
4 | Area 2 | Process 4
5 | Area 2 | Process 5

First dropdown I choose "Area 1" and second dropdown will display options "Process 1, Process 2, Process 3". Is it possible for using same script like -Casey_Roman although using query?

Use a parameterized named query, and use the first dropdown's value as the parameter to the second dropdown's query. That's it.


.

2 Likes

It's so simple more than I though, thankyou very much. I've wasted so much time on this.