SQLFORM.grid Add and Edit buttons incorrect links when running inside another view

42 views
Skip to first unread message

Flavio Bovio

unread,
Aug 17, 2019, 12:22:15 PM8/17/19
to web...@googlegroups.com

Add and edit button links are created incorrectly when the grid is inside another view. With the smartgrid works ok.

Add button link
http://localhost:8000/erp_proto/tablas_grales/index/addt/forma_pago                        Return None
Should be

Edit button link
http://localhost:8000/erp_proto/tablas_grales/index/edit/forma_pago/1                        Return None
Should be



CONTROLLER
def index():

    if request.args(0) == 'forma_pago':
        grid = SQLFORM.grid(db.forma_pago, csv=False, user_signature=False, details=False, advanced_search=False)
        return dict(grid=grid, enc='Formas de Pago')

    if request.args(0) == 'vendedores':
        grid = SQLFORM.grid(db.vendedores, csv=False, user_signature=False, details=False, advanced_search=False)
        return dict(grid=grid, enc='Vendedores')

    if request.args(0) == 'tipo_documento':
        grid = SQLFORM.grid(db.tipo_documento, csv=False, user_signature=False, details=False, advanced_search=False)
        return dict(grid=grid, enc='Tipos de Documento')

    if request.args(0) == 'situacion_iva':
        grid = SQLFORM.grid(db.situacion_iva, csv=False, user_signature=False, details=False, advanced_search=False)
        return dict(grid=grid, enc='Situaciones IVA')

VIEW

{{extend 'layout.html'}}

<div>
<h4>TABLAS GENERALES</h4>   
<div class="breaker"></div>
<h4 >
{{=A('FORMAS PAGO'    , _href=URL('tablas_grales','index', args='forma_pago')    , _class="btn btn_secondary")}}
{{=A('VENDEDORES'     , _href=URL('tablas_grales','index', args='vendedores')    , _class="btn btn_secondary")}}
{{=A('TIPOS DOCUMENTO', _href=URL('tablas_grales','index', args='tipo_documento'), _class="btn btn_secondary")}}
{{=A('SITUACION IVA'  , _href=URL('tablas_grales','index', args='situacion_iva') , _class="btn btn_secondary")}}
</h4>
</div>

<div class="breaker"></div>

<hr/>
<h4>{{=enc}}</h4>
{{=grid}}
</div>
</div>

Dave S

unread,
Aug 19, 2019, 5:26:10 PM8/19/19
to web2py-users


I'm not a grid expert, but looking at the gluon code, it appears the button code depends on the current grid name for generating Edit and Delete buttons.  You may want to look at the links argument to grid ("used to display new columns which can be links to other pages"), and is a dict with a column head value and a 'body" function that returns a value (such as an A() helper) when given a row.

See
<URL:http://web2py.com/books/default/chapter/29/07/forms-and-validators#SQLFORM-grid-signature>

/dps

Reply all
Reply to author
Forward
0 new messages