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.

1 Like

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?

2 Likes

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

Hello,

I came across this exact same question/issue earlier this week.

I am confident using python as a base language, so I started here:

Step 1. Draw a diagram how how the flow will go. Nothing fancy, just simple boxes with induvisual arrows that flow to the next state.

EX: Menu Options

  1. Food List = Burger, Salads
    Burger = [Single[LPCT, LPT], Double[LPCT, LPT]]
    Salads = [W/Dressing[Southwest, Ceaser, Summer], W/outDressing[Southwest, Ceaser, Summer]]
  2. Drink List = Soda[a, b, c], Coffee[black, w/sugNocream, NosugW/cream], Water, Juice
  3. Combo = friesdrinkListBurger,
    (This ex is bad just for demonstrating purposes)

Step 2. Using python, simple nested if else statements, with my diagrams equal to what I would call the functions or lists, and the list options labeled inside. I did nested lists and nested if/else because lists are extremely similar to datasets

Step 3. Create a CSV for EACH option, with an RID column and the List name as the second column. This is where using an actual example becomes important, because how you create the order is extremely important here. There isn’t a set way, and honestly it should be based on your flow diagram.
The more intuitive to the user you make it, the more “complicated” your coding will be. For example, when you pull up to a fast food line, you are able to see all of the options at once. Right? But you wouldn’t necessarily want to put drop down options for sodas or combos if the user is for sure selecting ONLY a sandwich, right? But then from the perspective of the user, lets say they only want to order the combo deal based on the type of drinks that are available. IF Orange soda is available, I want the chicken meal deal. IF not, I only want a sandwich. I need to then be able to see my list of sodas in order to determine if I want the meal deal, or a single item. This is where, in my opinion, all the different ways that you can develop become more solidified. Go to this next step, and create a draft with the simplest solution possible ,and if you notice the way you designed your order makes the available options in ignition hard, then go back and redesign.

Example:

Step 4: Impliment in to Ignition

The first version that I did listed several different datasets. Based on the levels of choice is how I determined my Dataset. So lets say, Level 1 yielded two options, and those two options yielded all different options. I created two different child datasets that included the RID value of the Parent, and I connected an Indirect Dynamic Tag link, which created a command to link the previous options selected from the parent, to the child. Based on what you click on with the parent, that string value gets translated to an integer value, a 1 or 0, and the indirect link then determines what data set to read from in the child, based on the one or 0 in the title of the data set. All of this sounds really complicated so maybe if I create an example based on the food menu, I can screen shot and share because it is actually quite simple:

Parent Dataset: Level0: 0,1 // Food, Drink

Child DataSet: Level1_0: 0,1,2, Burger, ChickeSand, Salad ; Level1_1: 0,1,2,3,4, // Water, Coke, Sprite,…blah blah)

So, that is Method 1, which is based on that earlier comment with the SQL solution. Ignition has basically built in scripting that allows for us to dynamically pull data. This option isnt great if you know the tables or titles of datasets will often change.

Option 2 is alot simpler, it is to use a container and use some command or tag relationship to view or hide the table based on certain constraints. Again, I am using my levels of options to determine the framework for this. Once I get everything up and made, if I am able to, I can create parallel examples based on food item menus and share this. I agree with your original post, I wish all of this was built in directly to ignition, or that there were atleast script snippets available to include online, which brings me to the third option

Option 3: If else statements in the scripts of each drop down component. This is my idea solution because it is based on python language, but personally I would create it in the container so that you aren’t stuck breaking down your script per each drop down component. This can create a huge headache later down the road with any language updates or just overall updates to Ignition or changes in your HMI.

I hope this helps!

I couldn’t make it past your 5th sentence. :slight_smile:

1 Like

I hope this helps :slight_smile:

Is this what you are looking for?

1 Like

What an essay for a question of 3 years ago xD And even a long video, nice :smiley:

1 Like

Yeah sorry about that, I am new here, and, I got a little too excited about the forum. You know what they say, a picture is worth 1000 words, I wonder how many video demos are worth? :wink:

Anyways, that was just one example of a possible solution. That one demos using dynamic indirect tag links, pic below on the scripting.

I personally recommend using that as a tool to help select the objects, and then copying and pasting everything in to a script of if else statements. I can try to create a demo of that if anyone would find it useful.

1 Like

Haha its nice to be excited :stuck_out_tongue: Not many would put so much time in replying something from so long ago xd

The video was nice indeed. i always include a screenshot image if im able too. I dont have a great video recorder tho, what did you use for it?

Thank you! It honestly wasn’t that much work. Software development is hard enough. PLC Industry can do some really cool things, but it is up to us to all come together online and share our findings on the backend development. It really only takes a second to capture and I think it saves so much time on my end and on the person who is trying to learn’s end. I will keep the videos in mind for future use on my questions and solutions to other questions!

I use snagit. I think my organization pays for it, although I am not sure.

I tried finding a free version, I think this is a link to that, although I didn’t really look in to it:

Here are some free alternatives:
(15 Best Snagit Alternatives in 2021 [Free & Paid])

1 Like

It’s not free…
Screenshot_36

I’m using Lightshot (it’s free)…
Screenshot_37