Hi! 

You can create a table in memory and use grid
working example:

def pro_report1():
    # https://web2py.wordpress.com/category/web2py-and-databases/
    # 
https://stackoverflow.com/questions/33674532/web2py-sqlform-grid-with-executesql
    tbl = 'proverka'

    #f_short_proverka = [  'f' + str(e) for e in short_proverka ]

    l = [e for e in db[tbl].fields if e in f_short_proverka ]
    memf = [ Field('oid', 'integer', label='П id', default= 0) ] + \
           [ Field(db[tbl][e].name, db[tbl][e].type, label = 
db[tbl][e].label,
             length= db[tbl][e].length, represent= db[tbl][e].represent  )
             for e in l ]

    dbmem = DAL('sqlite:memory')
    dbmem.define_table('mem_table',*memf)

    records = db(db[tbl].id>0).select().as_list()
    for r in records:
        r['oid'] = r['id']
        dbmem.mem_table.insert(**dbmem.mem_table._filter_fields(r))

    #dbmem.commit()

    flds= [ db[tbl][e] for e in f_short_proverka ]
    rows=db(db[tbl].id>0 ).select( *flds  )

    exportclasses=dict(
            csv_with_hidden_cols=False,
            csv=False,
            xml=False,
            json=False,
            tsv_with_hidden_cols=False,
            tsv= False,
            )

    dbmem.mem_table.id.readable = False
    grid = SQLFORM.grid(dbmem.mem_table, create=False, editable=False, 
exportclasses= exportclasses,
            deletable=False, buttons_placement = 'left', 
showbuttontext=False)
    return dict(rows=rows, l=l, records=records, grid=grid)

On Thursday, December 24, 2020 at 12:32:51 AM UTC+3 Vlad wrote:

> I'm getting the rows as a result of the select:
> *rows = db(query).select(*fields)*
> and want to display as 
> *table = SQLTABLE(rows, _class='table')*
> but before displaying need to reformat based on field representation, so 
> rendering first: 
> *rendered_rows = rows.render()*
> now I simply want to display the rendered_rows, like this: 
> *table = SQLTABLE(rendered_rows, _class='table')* 
> which is impossible because rendered_rows is a generator. I can iterate 
> row by row, but don't know how to use it with SQLTABLE. 
>
> Is there an easy way to transform the generator into the format that 
> SQLTABLE understands? 
>  
>

-- 
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 web2py+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/web2py/23e730b8-6522-4400-b034-7f9b912c345an%40googlegroups.com.

Reply via email to