Hi, I have 2 very simple questions.
I have followed the To Do’s tutorial here: https://anvil.works/learn/workshops/todo-list
all working ok, however I would like to do the following:
I want the rows to be separated by a line, or have alternated colors, so users can differentiate them. Is any way to do it?
I have been trying to save a “Done date” every time I check the box, so I know when the task was finished…but there is no way I can make it work, can you help?
Thanks!
One approach I use to alternate the color of rows in a repeating panel is as follows:
# in init
self.color_rows(self.repeating_panel_1)
def color_rows(self, rep):
for i, r in enumerate(rep.get_components()):
if not i%2:
r.background='theme:Gray 200'
This function goes in the form which holds your repeating panel. See the discussion here for more
details.
Please see the documentation on events here. You will want to use the datetime module to send a timestamp to your DataTables whenever the check event is triggered.
In the to-do tutorial you referenced, the author sets up a button click event that sends data to the DataTable. This is very similar to what you are attempting in terms of handling the event.
The timestamp can be returned as follows from the datetime module:
import datetime
datetime.datetime.now() # returns current date and time
Let us know how this goes and please share a code example if anything is unclear with these suggestions.
# in init
self.color_rows(self.repeating_panel_1)
def color_rows(self, rep):
for i, r in enumerate(rep.get_components()):
if not i%2:
r.background='theme:Gray 200'
and worked ok, however I needed to add a spacer to have some padding around the row.
I have read the documentation you link…will do some more experiments today.
Thanks!
I was anticipating you put the role on the datagrid.
With the role on the repeating panel then the following should work
(it won’t work in the designer but it will in the live app)
.anvil-role-striped > div > div:nth-child(even) {
background: %color:Gray 200%;
}
For more information on how to add a role for striped Repeating Panels. I figured out how to make this work in both the designer and while running. First, I made a role just for Data Grids and another just for Repeating Panels. Second, I added some JavaScript to the HTML to add one of two classes to the body depending on whether it was in designer mode or not.