开发者

web2py - display a SQL query in a form

i have 开发者_开发百科a SQL query

family_members = db(\
    db.member.parent_membership_id==parent_id.membership_id\
    ).select(\
    db.member.first_name, db.member.parent_membership_id)

I want to display "family_members" as a table in my form.

How can i do this?


In view:

{{=family_members}}


You can follow the example I've shown you in a previous question.

Make sure to also check the documentation on the web2py website, seeing the work you are doing with this framework I would recommend to buy the web2py official manual which is really not expensive and will save you a lot of precious time. You can also read it online from the link I gave you, or download a few free chapters.

Basically you have two options,

  • use the SQLTABLE
  • if you want further control on the table, you can transform the result given by the above option (it's a class you can use to modify the contents), or create it entirely on your own with the HTML helpers (TABLE and so on, from the gluon library).

To illustrate that a little bit:

family_members = db(...).select(...) # your rows construct
table = SQLTABLE(family_members, orderby=True, _class='sortable', _width="100%")

If you want to add a column, for example:

table[0][0].append(TH("details"))
for i, value in enumerate(table[1]):
    table[1][i].append(TD("line %d" % i, _align="center"))
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜