After some experiments I settled with simple grid 

ftp://ftp.akl.lt/users/jurgis/web2py/images/grid_for_nested_tables.png

You can also see 4 extra headers which mean tables, that are nested.

I used jQuery to make repeating table-rows invisible and incorporate extra 
headers
but this could be done with 
http://web2py.com/books/default/chapter/29/05#elements
just jquery option would help if table had client side sorting...

***
to join nested tables I came up with some pattern -- first I describe 
tables 
from most parent, to most child...  
and each except first has indicated field, which connects/references the 
previous table

    tables_info = [
        #(table, ref_field, fields, constraints, links)
        ('Klientai',    None ,            ['name'],  [], None), # ['name', 
'addresas']
        ('Pacientai',  'seimininkas',     ['rusis', 'name'] , [] , None),
        ('Paskyrimai', 'pacientas' ,      ['kada', 'apie', 'sumoketa'] , [] , 
[] ), # [dict(header='bendra_kaina', body=lambda row: row['bendra_kaina3'])]
        ('Pardavimai', 'paskyrimas' ,     ['sandelio_produktas', 'kiekis', 
'kaina'] , [] , None),
    ]

def nested_tables_grid(tables_info, query=None, left=None):

         fields = []
         total_links = []
         table_joins=[]
         for nr, (table, ref_field,  field_names, constraints, links) in 
enumerate(tables_info):
             fields.extend( [db[table][field] for field in field_names] )
             if links: total_links.extend( links )
             if ref_field:
                 table_joins.append( db[table].on( db[table][ref_field] == 
db[tables_info[nr-1][0]]['id'] ) )
                 # db.Pacientai.on(db.Pacientai.seimininkas == db.Klientai.id) ,

         if left != None:
             table_joins = left

         query = query  or  db[tables_info[0][0]] #db.Paskyrimai

         # response.flash += str([query , fields, field_names])

         return DIV 
<https://jurgis.pythonanywhere.com/examples/global/vars/DIV> (
                  # SQLTABLE(db(query).select() ),
                  SQLFORM 
<https://jurgis.pythonanywhere.com/examples/global/vars/SQLFORM>.grid(query, 
left=table_joins, showbuttontext=True,  fields=fields, links=total_links, # 
orderby=[ db[tables_info[0][0]] ['id'] ],
                  editable=True, user_signature=False),
                )


grid = nested_tables_grid(tables_info, query=db.Paskyrimai)

# I think this fullfills Zen of Python "Flat is better than nested. 
<http://www.python.org/dev/peps/pep-0020/>" :)


-- 

--- 
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