How to change viewing / editing pages of smartgrid component in web2py

The smartgrid component in web2py is very powerful. I wonder if it is possible to add additional markup to the pages of viewing / editing a smart file.

Normally, in web2py we need to create a view html file corresponding to the function in the controller. The problem with smartgrid is that the controller functions are automatically determined by the component.

For example, clicking the browse button in smartgrid goes to the following URL:

default/index/dataset/view/dataset/1 

Now, the question is, can I create my own HTML view file for this page, which may contain things other than smartgrid?

+4
source share
1 answer

The smartgrid component does not automatically detect controller functions. Rather, links for viewing, editing, etc. They simply pass additional arguments to the same function where the smartgrid is defined (for example, in the URL above, dataset/view/dataset/1 - all the arguments to the index function, which, apparently, is where your smartgrid is defined).

You have at least two options. First, you can add conditional logic to the index.html view, for example:

 {{if 'view' in request.args:}} [special code for viewing a record] {{else:}} [regular grid view code] {{pass}} 

Alternatively, you can specify a different view from the controller function, for example:

 def index(): if 'view' in request.args: response.view = 'default/view_record.html' [rest of index code] 
+3
source

Source: https://habr.com/ru/post/1381508/


All Articles