Searching data table with repeating panel

What I’m trying to do:
I have a search button in the admin section which is supposed to use the selected employee to search for all users that match the employee email and display it in the repeating panel. The system does not give me any errors, it just won’t display anything. I printed out employee_searched and it should match whats in the data table users. Idk
Any thoughts as to what I am doing wrong?

def button_search_employee_punches_click(self, **event_args):
    employee_searched = self.drop_down_employee_punches.selected_value
    self.repeating_panel_employee_clock_ins.items = app_tables.clockinoutsystem.search(Users=employee_searched)

Clone link:
share a copy of your app

There’s something up with your logic here. When I clone your app and tweak the data tables it appears to work fine (maybe you’ve fixed it since posting, but I’m not totally clear how the drop_down_employee_punches is populated and how that relates to the app_tables.clockinoutsystem table). The code for button_search_employee_punches_click seems fine though.

You do a lot of stuff with strings. Have you considered using row links between tables? That’ll help clean up some of what you have going on.

What did you actually tweak? The code itself should work logically, but it doesn’t on my end. I did not fix anything or changed anything yet.

The funny thing is I had another copy of this app and I was testing and got it to work there, but I cannot seem to duplicate it on this version. I’m stumped really.

This bit of code is how we get that dropdown menu.

    # Dropdown menu for Employee Emails
    employee = [(str(d['Company_Representatives']),d) for d in app_tables.company_info.search(Email=self.user_name.text)]
    
    employee_list = []
    for t in employee:
      employee_list.extend(t[0].split(','))
    
    self.drop_down_employees.items = employee_list
    

The bit of code above is just reused.

# employee clocks 
    self.drop_down_employee_punches.items = employee_list

I isolated the issue but I cannot fix it.

The employee_searched variable holds the right variable and format.
The repeating panel also searches the right data table when I just search for all records, however, the issue is that it won’t search for the specific record I want based off of the dropdown menu selected.

I printed out the dropdown selected value and it is correct as it should be in the data table. I think this must be an #bug-reports Anvil bug. If there were any errors on my part, I would assume it would show up in the logs, but nothing.

You might show the results of the printouts, and screenshots of the data tables. Your app is such that it’s difficult to run it with a new login and get anything useful out of it to test it. As it is, maybe there’s a subtle difference causing the issue, but without seeing what you’re seeing, nobody can offer advice.

Logic errors just end up with incorrect output, and don’t show up in the logs.

I completely understand @jshaffstall . Here is the screenshot of the data table that I want to display. It tested it for the first row and it does not come up in repeating panel.

Here is the code that I sued to print out the employees_search variable.

  def button_search_employee_punches_click(self, **event_args):
    employees_search = self.drop_down_employee_punches.selected_value
    self.repeating_panel_employee_clock_ins.items = app_tables.clockinoutsystem.search(Users=employees_search)
    print(employees_search)

Here is the screenshot of the printout.

I’m not sure which of the prints is the print(employees_search) one. There’s a blank line between the two emails. Do you have a blank print() somewhere, or is there an end of line sneaking into the string somewhere?

You might try printout out your employee_list just after you build it, to see if there are extra end of lines in those entries.

I printed the employee list and my selected user.

Here is the code for the employee list

# Dropdown menu for Employee Emails
    employee = [(str(d['Company_Representatives']),d) for d in app_tables.company_info.search(Email=self.user_name.text)]
    
    employee_list = []
    for t in employee:
      employee_list.extend(t[0].split(','))
    
    self.drop_down_employees.items = employee_list
    print(employee_list)

I do not have a blank print() or at least not aware of. I just clicked on the Search button twice.

Look at the printout for your employee list. There’s an end of line marker in the last email, the one you’re trying to search on. That will make it not match the string in the data table.

Backtrack the creation of that list to try to work out where the end of line is coming from.

1 Like

It seems as if it’s creating a new line in the textarea. How would you go about removing “\n” and splitting that list with “,” ?

Would it be more simple if I just replaced the textarea with textbox?

Sorry for delay in responding.

What I found is that the drop-down is populated from employee_list which is effectively the Company_Representative column from the Company Info table.

You then search the clockinoutsystem table using the value from your dropdown, i.e. the company_representative.

At least at the time of cloning, the “company representatives” I selected from the drop-down had no data associated with them in the ClockInOutSystem, so the repeating panel had no data.

I just tried your app, and put myself in charge of “Garoot Marketing” (by adding my email to the Email column and making myself a user with that email), and leo@gmail.com data showed up as expected:

Firstly, kudos - this isn’t a trivial app you’ve built out here so well done. I’ll make a suggestion though: You store a lot of data as strings that can be stored either as a link or a simple object.

  • You store Company_Representative as a comma-delimited string and parse that in your code. You can simply store it as a list of strings in a simple object column.
  • You exclusively store refence to Users as their email in string format. You’re better off storing a reference to a user row. Similarly, if users are always part of a company, you can link to the company from their row.

If you implemented these recommendations, the following code:

    employee = [(str(d['Company_Representatives']),d) for d in app_tables.company_info.search(Email=self.user_name.text)]
    
    employee_list = []
    for t in employee:
      employee_list.extend(t[0].split(','))
    
    self.drop_down_employees.items = employee_list

would be reduced to:

    self.drop_down_employees.items = anvil.user.get_user()['company_link']['Company_Representatives']

Or, if Company_Representatives was a multiple reference to the users table:

   reps = anvil.user.get_user()['company_link']['Company_Representatives']
   self.drop_down_employees.items = [(rep['email'], rep) for rep in reps]

And the drop_down_employees.selected_item would return a user row, which you could use for subsequent searching etc. I guarantee this would help with your debugging as well.

You can easily remove characters using replace, e.g.:

text = text.replace("\n", "")
1 Like

@danbolinson Your tips here would have been excellent when I began this project. This is my first project on Anvil and the first significant python project I decide to learn and build. It seems like it’s way to complicated to implement a total restructuring right now or am I just overthinking it?

I am a visual learner and was wondering if you have any examples of link or simple object apps implemented so I can study them for any future apps. I went through the docs but the examples there are so trivial and hard to implement into something more complex and specific.

Also, it could be me being new.

@jshaffstall yet again you solved the problem. It was \n and spaces between “,”.

In the text area I would space out my users emails. Example: jeff@gmail.com, Mike@gmail.com. Now without spaces and \n removal code, I got it to work as intended. Appreciate the help :slight_smile:

1 Like