If you benefit from web2py hope you feel encouraged to pay it forward by contributing back to society in whatever form you choose!


  • 0
    iiijjjiii  13 years ago
    The only variable data associated with a "formatter: showlink" column is the id of the record. So we have to work with that. Create a link_handler function to redirect it properly.
            'colModel': [
                {
                    'name': 'akb_journal',
                    'formatter':'showlink',
                    'formatoptions':{
                        'baseLinkUrl': 'link_handler',
                        },
                },
    
        def link_handler():
            article = db(db.akb_articles.id == request.vars.id).select().first()
            if not article:
                session.flash = 'Invalid article id: %s' % request.vars.id
                redirect(URL('???'))
    
            journal = db(db.akb_journal.uuid==article.journal).select().first()
            redirect(URL('journal_edit', args=[journal.id]))
    
    If you have more than one column formatted as a link, then pass a parameter along indicating the field. All links go to the same link_handler function, which redirects appropriately.
            'colModel': [
                {
                    'name': 'akb_journal',
                    'formatter':'showlink',
                    'formatoptions':{
                        'baseLinkUrl': 'link_handler',
                        'addParam': '&field=akb_journal',
                        },
                },
                {
                    'name': 'akb_table',
                    'formatter':'showlink',
                    'formatoptions':{
                        'baseLinkUrl': 'link_handler',
                        'addParam': '&field=akb_table',
                        },
                },
    
        def link_handler():
            article = db(db.akb_articles.id == request.vars.id).select().first()
            if not article:
                session.flash = 'Invalid article id: %s' % request.vars.id
                redirect(URL('???'))
    
            if request.vars.field == 'akb_journal':
                journal = db(db.akb_journal.uuid==article.journal).select().first()
                redirect(URL('journal_edit', args=[journal.id]))
    
            if request.vars.field == 'akb_table':
                redirect(URL('table_edit', args=[article.table_id]))
    

Commented on:

Here is a JqGrid application that includes a JqGrid module that allows you to insert jqgrid tables in web2py pages using python. git clone https://iiijjjii@github.com/iiijjjii/jqgrid.git The module includes functionality for searching and form editing as well as the general features, pagination, sorting on columns, formatting and navigating available with jqgrid. The application includes examples of usage in the default.py controller.

Hosting graciously provided by:
Python Anywhere