Mert Nuhoglu
Mert Nuhoglu

Reputation: 10143

How to change view/edit pages of the smartgrid component in web2py

Smartgrid component in web2py is very powerful. I wonder if it is possible to add any additional markup into the View/Edit pages of the smartgrid.

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

For example, clicking the View button in a smartgrid goes to the following url:

default/index/dataset/view/dataset/1

Now, my question is if I can create a custom view html file for this page that can contain things other than smartgrid?

Upvotes: 4

Views: 1884

Answers (1)

Anthony
Anthony

Reputation: 25536

The smartgrid component is not automatically defining controller functions. Rather, the links for view, edit, etc. are simply passing additional arguments to the same function where the smartgrid is defined (e.g., in the above URL, dataset/view/dataset/1 are all arguments to the index function, which presumably is where your smartgrid is defined).

You have at least two options. First, you could add conditional logic to the index.html view, such as:

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

Alternatively, you could specify a different view from within the controller function, such as:

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

Upvotes: 3

Related Questions