You can just do

{{=SQLTABLE(rows, headers=dict([('mytable.'+f,db.mytable[f].label) for
f in db.mytable.fields]))}}

On Sep 10, 1:07 pm, villas <[email protected]> wrote:
> I see it may not be straightforward, but if I may still make a non-
> urgent suggestion for future consideration:
>
> 1. Check whether it's a normal looking, unambiguous fieldname.
> 2. If true, and a label exists,  then use the label.
>
> After all, if there are any problems with column headers, we could
> still set them manually as at present. I'm just trying to make things
> easier for the most common case,  a standard field column which may
> have a label.
>
> Best wishes, David
>
> On Sep 10, 6:28 pm, mdipierro <[email protected]> wrote:
>
> > This comes up once in a while and the answer is no.
>
> > The problem is that SQLTABLE may need to display the result of a join
> > where the same field appears has two columns and some columns may be
> > computed from expressions. They do not have a label and even if they
> > do, using label would be confusing. This would require so much
> > configuration that the best solution is NOT to use SQLTABLE but just
> > loop over the rows.
>
> > Massimo
>
> > On Sep 10, 11:43 am, villas <[email protected]> wrote:
>
> > > It seems strange that the db.field 'label' is not used as the column
> > > header by default in SQLTABLE.  After all,  if someone has gone to the
> > > trouble of specifying a 'label',  surely they would wish to use it
> > > everywhere.  I eventually found this excellent tip from Massimo.
>
> > > Controller:
> > > headers=dict([(c,db[c.split('.')[0]][c.split('.')[1]].label) for c in
> > > rows.colnames])
>
> > > View:
> > > {{=SQLTABLE(rows, headers=headers)}}
>
> > > Please could we add this functionality to the core?  Or, at least
> > > include it in the book, (sorry if I missed it).
>
> > > Thanks.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to