Use dropdown to display datagrid

I have a dropdown and want to use the dropdown to control which data table to display in the repeating panel in form1, how am I suppose to do that. I tried to change the repeating_panel.item to the correct data_base.search() with the condition of dropdown.selected_item == “the item that I need”, but it wouldn’t work

I guess what better describe my issue is what is the correct event for selecting different element from the dropdown, is it the “change event?”

Hello and welcome,

You are probably not that far away from getting it to work based on your description; however, if you could be more specific about what didn’t work, we could help more easily.

For example, you could share a more complete snippet of code, include the exact error you are receiving, and if possible share a simple clone app to demonstrate the issue (i.e., click on the :gear: icon in the IDE and follow the instructions).

Here are some general guidelines for ensuring that you get a helpful response.

Also, you may find the learning resources helpful.

Yes, the change event of the drop down component will be triggered when the selected value is changed.

For example,

  • Set the function name in the IDE (if it is not already)
    sc1

  • Write a function to handle the change event
    sc2

In my form1 constructor I have 2 elements for the dropdown

self.drop_down_1.items = ["Apple", "Banana"]

then I select the event “change” and wrote this:

def drop_down_1_change(self, **event_args):

    """This method is called when an item is selected"""

    if self.drop_down_1.selected_value == "Apple":
      print("Apple is selected")
      self.repeating_panel_1.items = anvil.server.call('get_apple_data')

    if self.drop_down_1.selected_value == "Banana":
      print("Banana is selected")
      self.repeating_panel_1.items = anvil.server.call('get_banana_data')

However, in the output, I cannot see the message that is supposed to be printed

It seems to me that drop_down_1 and drop_down_1_change are not rigged up together. That is my guess. Perhaps you did not add the function to the event handler (as shown above).

Here is an app to demonstrate. It prints the selected value when the value has changed. Similar logic to your above code.

https://anvil.works/build#clone:XJBCA2E5PHSCEGAL=HTMLAKU423CGCQ7KQDUB4KGZ

Does this app help to clarify things?


To help others more easily read your code please format code by wrapping it in backticks with the word Python.

For example,

```python

print('this will be syntax highlighted')

```

I figured out the issue, my event name changed to name_box for some reason, it also happens for some other events, why it will change name by itself?

I have not experienced function names for events changing by themselves.

Can you take a GIF of that happening, or reproduce this in some way? I’m sure the Anvil developers would take a closer look as that would be a bug.