Hello! Hope everyone is having a great day! Running into a slight issue that I hope you guys can help out with.
I have a form with a dropdown, button and datagrid. The datagrid is filled with the unique years from a table called Cases. What I am looking to do is when the page initially loads it shows only data from the year selected in the dropdown. If the user changes the year it should refresh and show the cases from the year selected. Unfortunately I am hitting a wall on how to do this. Here is what I have so far:
class CasesComponent(CasesComponentTemplate):
def __init__(self, **properties):
# Set Form properties and Data Bindings.
self.init_components(**properties)
# Any code you write here will run before the form opens.
item_list = set((str(r['opened_date'].year) for r in app_tables.cases.search(tables.order_by("opened_date", ascending=False))))
self.years.items = item_list
year = datetime.date(list(item_list)[0])
print(year)
self.refresh_cases(year)
def refresh_cases(self, year):
# gets unique list of date years from the cases table
self.repeating_panel_cases.items = anvil.server.call('get_cases', year)
Server Module code:
@anvil.server.callable
def get_cases(year):
# get a list of cases
return app_tables.cases.search(opened_date=year)
I know the code is wrong in two places, but I can’t seem to figure it out.
Thanks in advance!