[Fixed] Does canvas in DataGrid work only on first page?

I don’t understand why the canvas on my app only works on the first page of a data grid. I think it is a bug, but I might be missing something.

This test app has these components: data grid - repeating panel - row template - canvas:
https://anvil.works/build#clone:WVVMXLRMPKPV6UJ3=VB4MQRPJE3JJNH3V7WZMBUEA

The canvas is updated on 4 places: the __init__ and the form_show of the row template form, the canvas_1_show and the canvas_1_reset events.

It looks like the __init__ has no effect because the canvas is not yet ready, but the form_show, canvas_1_show and canvas_1_reset are doing their job.

Everything works well when the data grid shows the first page, but when navigating to any other page, including going back to the first page, the update_canvas function is called, but the canvas doesn’t show any graphics.

Adding self.canvas_1.reset_context() (and removing the canvas_1_reset event) before each redraw doesn’t help.


Below a snapshot of the real app.
I was able to get it to work by setting a timer’s interval to 0.01 on each form_show, then calling the function that updates the canvas on the tick event. It works, but there is some nasty flickering (because the whole page is shown first without graphics, then with graphics) and other side effects that I really would like to avoid:

1 Like

If you resize the window when the second page is showing, that triggers the canvas reset event and you can then see the final square drawn. I can only imagine that the data grid paging mechanism is doing something that ends up clearing the contents of the canvas but not triggering the reset event.

1 Like

Thanks for the app that reproduces the error - very clear.
We’ll look into that and update this thread.

1 Like

This should now be fixed.

2 Likes

Thank you.
I removed the timer and used the canvas_reset event, and now everything works well and it’s smoother.

1 Like