opening different grids with the same controller in a multi-tabs form(seeking for confirmation)

36 views
Skip to first unread message

Carlos Kitu

unread,
Oct 26, 2015, 6:39:51 AM10/26/15
to web2py-users
Hi, I have a sqlform with four tabs. There is a main form and 4 additional tabs. In each tab there is one grid with a related table to the one in the main form (1 to many relationship), and they are loaded gracefully using the LOAD function and ajax. 
In my first version, I used a separate function/view for each grid, they are called by every LOAD command, and everything worked fine.

The next time I needed something like that, I thought that writing 4 functions/views for the grids was too redundant as each function was quite similar to the other, and I only needed to change a few parameters (table name, related field) and decided to create a single function with the corresponding parameters to show the corresponding table in each tab/grid.
Everything seemed to work fine, but in my tests, I noticed that when I created a new record in one of those tabs, and there was an automatic reload of the grid (in grid mode), it always displayed the last grid loaded in the initial load of the tabs. Pushing F5 and forcing an initial reload of the multi-tabbed form, forced every grid to display properly.

Digging into SQLFORM.grid, I noticed a line:
referrer = session.get('_web2py_grid_referrer_' + formname, url()) 
That could explain why I'm always getting the last grid loaded in the initial load of the multitabbed form. I would like to confirm this and ask you if there would be any workaround not dependent on a session variable, that for sure will cause concurrency issues.

Best regards and thankyou for this helpful group. 

Carlos Kitu

unread,
Oct 26, 2015, 6:45:12 AM10/26/15
to web2py-users
By the way, I just noticed pushing the "Back" button in the main form (not loaded with ajax, just a normal grid created by a controller), that it is also pointing to the url of the last loaded grid. Probable another side effect of the same problem.

Best regards.

Vinicius Assef

unread,
Oct 26, 2015, 7:11:21 AM10/26/15
to web2py
You can try filling the `formname` argument of SQLFORM.grid().




--
Vinicius Assef



--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups "web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to web2py+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Carlos Kitu

unread,
Oct 26, 2015, 7:43:55 AM10/26/15
to web...@googlegroups.com
Vinicius, thank you so much for your help. It worked fine.

I also realized that I had the answer right under my nose.
The formname in referrer = session.get('_web2py_grid_referrer_' + formname, url()) wasn't for nothing :-D

Best regards.
Reply all
Reply to author
Forward
0 new messages