Dynamic drop down lists

I would like to use the selections from one drop down to control and alter what can be selected on another drop down. Is this possible in ignition and if so any assistance on the script would be appreciated.

Sure. Use the selectedValue or selectedStringValue from the first dropdown in the where clause of the binding that gets the rows to show in the second dropdown. Any change to the first will cause the second to refresh.

I apologize but being new to python can you provide a quick script of how to code that. If i have a starting point i can usually figure everything else out.

Let me explain it differently. The first drop down list will have many items. Based on which item is selected the second drop down box will display different lists. Kind of like selecting a state and city but the cities in the drop down change based on what state you select.

Where are you getting the raw datasets (pre-filtering) from? Phil’s suggestion is based around data coming out of a database, in which case you won’t even need scripting.

1 Like

That is one of the items i still need to do. I am trying to figure out how to get one to affect the other before i proceed with my data sets.

The method changes depending on where you are getting the raw data from. Is it a dataset tag? Database table?

We already have a database for our PLC interfacing. I was going to use that to create a table for downtime reporting of machines using manual reporting. I was going to create a new database for this but did not want to do something to affect the existing one.

Well somewhere you have to be storing the relationship between the two drop down lists, and a database is probably the best place to do that.

Here is a really basic example with a city and state table. (This is not a good database setup).

    state                   city
+------------+  +-----------+--+------------+
| stateName  |  | cityName  |  | stateName  |
+------------+  +-----------+--+------------+
| Alaska     |  | Anchorage |  | Alaska     |
| Montana    |  | Billings  |  | Montana    |
| Washington |  | Bozeman   |  | Montana    |
|            |  | Fairbanks |  | Alaska     |
|            |  | Juneau    |  | Alaska     |
|            |  | Missoula  |  | Montana    |
|            |  | Seattle   |  | Washington |
|            |  | Spokane   |  | Washington |
|            |  | Vancouver |  | Washington |
+------------+  +-----------+--+------------+

For the first (State drop down) you would use a query like this to populate the data property.
SELECT stateName FROM state ORDER BY stateName

Then… On the second (City) drop down, use a query something like this.
SELECT cityName FROM city WHERE stateName = {Root Container.State.selectedStringValue}

That query will return the cities that correspond with the selected state.

Does that help?

Hey, @christopher.raphael.

I am sure that there is more than one way to accomplish this, but this is how I have set it up on previous projects.

Say you have two drop-down lists, I’ll call them drpParent and drpChild (its values depend on the selection made on drpParent).

I would bind the Data property of the drpChild using:

  1. Expression binding type:
runScript('project.myProject.get_children', 0, {Root Container.drpParent.selectedValue})
  1. SQL Query binding type:
SELECT columns 
FROM tablename
WHERE parent_id = {Root Container.drpParent.selectedValue}

As @Stuart suggests, for this to work your Data property of drpParent must be bound to an Expression, SQL Query, statically, or however you prefer.

I think you’re missing your function definition for get_children