Hi, I have a table of clients with columns for name, address, phone, mobile, email, business type etc. I would like to have a repeating panel (or data grid) with a list just showing just names and business type and a button which I could use to open a form showing all of the data on that client. Is this something that is or will be possible to achieve? Thanks
Have you gone through the data grid tutorials? Anvil | Displaying Data In Tables
The later ones show how to add buttons into the rows that can perform tasks on that row.
That is 100 percent doable!
I would clone this tutorial because it walks you through exactly how to do it and you can follow along
In short,
- drop a data grid onto an open form.
- select âAdd Columns from Data Tableâ on the properties window (to the right of your screen)
- Delete the Columns your not interested in.
- Add a column for your edit button.
The tutorial will walk you through all of that process. Where it starts to deviate from what you want is the open form process.
Here is an edited version of the tutorial with an âeditâ button that opens another form:
Hope this helps!
Hi, thanks for your message. I checked out these tutorials, and they got me part way to what I want but not the getting all of the fields (including those not shown in the repeating panel) from the data table and showing them on a new form.
Hi, thanks your message. I am getting closer now. I see now how to redirect to a new form. Just need to figure out to get the data from the data table and display on new form (sorry, still quite new to this).
If you share what youâve tried, thatâll help folks here offer advice in context.
No problem! I am going to write really loose code and let you fill in the gaps or ask more questions.
- Update your new form to take in a row_id in the init method.
- Update the open_new_form_button_clicked method (in your rowtemplate code) to pass in row_id into the open_form(form(row_id))
You can do this by calling self.item.get_id()
- Add method to your server code to find row by row id
app_tables.table_name.get_by_id(row_id)
- call that method from your new form with the row id
- fill in your form with that customer information!
Have fun coding!
Hi, thank you for your previous detailed reply. I have been going through the tutorials and all ok until I try to use the get_id() command. Would you mind please going into a little more detail about where this command should be and the format.
Table: app_tables.contacts
Form (showing just ânameâ and âcompanyâ) with view/edit button: ContactsComponent
Form to open and display ALL the contact data (when view/edit button clicked): ContactDetailsComponent
Server module: get_contact_id
Hope itâs appropriate to ask all that and thanks in advance.
I believe the get_id method is only available to a database row object. So once you run your search or get operation, on a single row run the get_id method on it and it will return that rows unique id.
thanks, that makes sense. In the docs it shows searching on a specific row where the name is known and entered. My problem is I am selecting a name from the repeating panel depending on which âview/editâ button I click. Hope that makes sense.
If what you are saying is that you want to get a single row baaed on the name you get back from the button clicked, that would be app_tables.my_table.get(queries).
Unless you get an id from the button, then you would replace the get with get_by_id(id)
First I am going to continue on the path I sent you, but offer an alternative method afterwards.
option 1:
So you would have a method in a server module that would look something like this:
@anvil.server.callable
def get_contact_by_id(id):
return app_tables.contacts.get_by_id(id)
You put this method in a server module for security reasons you can read up more on that with some googling.
Once you put this method in your server module, you should be able to call in from your button_clicked method in your ContactsComponent.RowTemplate Form:
def button_clicked(self,**event_args**):
open_form(ContactDetailsComponent(self.item.get_id()))
Then in ContactDetailsComponent.init() you can call that server method to get all the information:
def __init__(self,item_id):
self.contact = anvil.server.call('get_contact_by_id',item_id)
option 2:
You donât have to create server module and pull the id. instead you can just pass the item to the ContactDetailsComponent form directly from your row:
def button_clicked(self,**event_args**):
open_form(ContactDetailsComponent(self.item))
and in the init of the ContactDetailsComponent you can take in item directly:
def __init__(self,item):
self.contact = anvil.server.call('get_contact_by_id',item)
Thank you for that. Very helpful.
Thank you for the detailed solution. I have got it working now