I want to use SQLFORM.grid with selectable checkboxes to serve a custom 
export function. Unlike web2py's default exportformats manager, which 
triggers each exporter function to an <a> tag, I want my exporter to 
trigger when the user clicks the form submit button. So the user flow 
involves ticking some grid row checkboxes, clicking submit, getting a Save 
As dialog, and finally saving the downloaded export data as a local file.

controller:
def export_rows(selected_ids):
    def export():
        ret = []
        rows = db(db.mytable.id.belongs(selected_ids).select()
        for row in rows:
            ret.append('%s\r\n' % myformatter(row))
        return ret


    fileext = 'tab'
    content_type = "text/tab-separated-values"
    filename = '.'.join(('test', file_ext))
    response.headers['Content-Type'] = content_type
    response.headers['Content-Disposition'] = \
        'attachment;filename=' + filename + ';'
    raise HTTP(200, export(), **response.headers)


return dict(grid = SQLFORM.grid(db.mytable, selectable=export_rows))


The above code works to export the rows according to the user flow. 
However, web2py.js disables the submit button when the user clicks it and 
the button is never re-enabled, because raise HTTP transfers control away 
from the page and back to web2py, so the page is never refreshed.
How to re-enable the submit button, or not disable it to begin with? 
TIA

-- 
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 [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to