Contextual drop down from data table

I’m currently using the basic method from the example video to populate my first drop-down

self.dd.items = [(r['name'], r) for r in app_tables.stuff.search()]

from here i need a second drop-down to show the other column values from the first selection.

full code would look something like:

self.dd.items = [(r['name'], r) for r in app_tables.stuff.search()]

def dd_change(self, **event_args):
    self.dd2.items = ---selected row, cells for value1 and value2---

dd is drop down 1
dd2 is drop down 2
stuff is the data table (col = name, value1, value2)

new to this, sorry about formatting etc

Hi @l.mich welcome to the forum!

It seems like value1 and value2 are dependent on the selection in dd? So I don’t think I would use a second DropDown unless you want to be able to make selections with it…

I have a couple of suggestions. You could change the dd.items property to be as follows:

self.dd.items = [(f"{r['name']} - {r['value1']} - {r['value2']}", r) for r in app_tables.stuff.search()]

This way the displayed option is the name, value1 and value2 and the row is what is selected.


Alternatively keep the current approach but have two Labels next to the dropdown. Change their text property on the dd_change event.

self.dd.items = [(r['name'], r) for r in app_tables.stuff.search()]

def dd_change(self, **event_args):
    row = dd.selected_value
    self.label_value1.text = row["value1"]
    self.label_value2.text = row["value2"]

Does that help or am I missing something?

If I understand all you need is this:

def dd_change(self, **event_args):
    self.dd2.items = app_tables.stuff.search(column1=self.dd.selected_value)

yea just to clarify, i need to select form Value1 and Value2 in the second dropdown. This looks like it might solve my problem. Gonna try implementing and see where we get

Ah I see… so then

def dd_change(self, **event_args):
    row = dd.selected_value
    self.dd2.items = [row["value1"], row["value2"]]

1 Like

the problem with self.dd.selected_value, is that when used this way, it stores the value as a row object, not a string value

this does it perfectly. amazing, ty

Please consider marking the post as the solution (it’s a check box), so as to help others who may come across this thread.

3 Likes