how to remove column header

55 views
Skip to first unread message

Alex Glaros

unread,
Oct 14, 2016, 9:35:51 PM10/14/16
to web2py-users
how to supress field header

   {{taxonomy_set = ['super_city_3', 'super_city_2', 'super_city_1', 'city', 'sub_city_1', 'sub_city_2', 'sub_city_3']}}
    {{for r in taxonomy_set:}}
        {{db.geo_political_generic_fields_lookup.taxonomy_column_fk.label = ''}} #does not work
        {{geoFieldName = db((db.geo_political_generic_fields_lookup.country_fk == specificCountryID) & (db.geo_political_generic_fields_lookup.generic_geo_political_field_name == r)).select(db.geo_political_generic_fields_lookup.taxonomy_column_fk)}}
        <b>{{=r }}</b>   translates to: {{=geoFieldName}}<br>
    {{pass}}

PRODUCES

super_city_3 translates to:
geo_political_generic_fields_lookup.taxonomy_column_fk  # want to remove this header
Federal US government
 
super_city_2 translates to:
geo_political_generic_fields_lookup.taxonomy_column_fk # want to remove this header 
State

super_city_1 translates to:
geo_political_generic_fields_lookup.taxonomy_column_fk # want to remove this header
County

thanks,

Alex Glaros

Massimo Di Pierro

unread,
Oct 15, 2016, 1:22:00 PM10/15/16
to web2py-users
I do not full understand. You select only the column db.geo_political_generic_fields_lookup.taxonomy_column_fk
what d you want you want to remove it? You want to remove the header only?

You could replace {{=geoFieldName}}
with 
<table>{{for row in geoFieldName:}}<tr><td>{{=row.taxonomy_column_fk}}</td></tr>{{pass}}</table>

Anthony

unread,
Oct 15, 2016, 4:27:23 PM10/15/16
to web2py-users
On Friday, October 14, 2016 at 9:35:51 PM UTC-4, Alex Glaros wrote:
how to supress field header

   {{taxonomy_set = ['super_city_3', 'super_city_2', 'super_city_1', 'city', 'sub_city_1', 'sub_city_2', 'sub_city_3']}}
    {{for r in taxonomy_set:}}
        {{db.geo_political_generic_fields_lookup.taxonomy_column_fk.label = ''}} #does not work

The "label" attribute is used in forms -- not relevant here.
 
        {{geoFieldName = db((db.geo_political_generic_fields_lookup.country_fk == specificCountryID) & (db.geo_political_generic_fields_lookup.generic_geo_political_field_name == r)).select(db.geo_political_generic_fields_lookup.taxonomy_column_fk)}}
        <b>{{=r }}</b>   translates to: {{=geoFieldName}}<br>
    {{pass}}

The problem is that geoFieldName is the result of a .select(), so it is a Rows object -- when you insert a Rows object in a template, you get a SQLTABLE (with headings). Instead, you need .select(...).render(0).taxonomy_column_fk. The .render(0) extracts the record from the Rows object and applies the "represent" attributes of each of its fields (in this case, just the taxonomy_column_fk field). If you instead did .select(...).first().taxonomy_column_fk, you would get the actual foreign key value (i.e., an integer record ID) rather than the transformed representation of that foreign key.

Also, I would recommend moving most of that code out of the view -- views are for displaying data, not creating/generating it. Code in views is harder to read and debug.

Anthony

Alex Glaros

unread,
Oct 15, 2016, 5:34:02 PM10/15/16
to web2py-users
thanks Massimo and Anthony

it's working now but don't know how to get around writing a loop in the view.  Can you please explain in general principles how to get loop written in controller to display in view?

Anthony

unread,
Oct 15, 2016, 5:53:21 PM10/15/16
to web2py-users
You can do a loop in the view -- just prepare a data structure in the controller and pass it to the view (i.e., move the queries to the controller). Actually, you can probably just do a single query including all items in taxonomy_set (and orderby that field) -- then just send the entire Rows object to the view and loop through it. Note, you should also probably avoid using the .render() method to translate each foreign key to its represented value, as that will issue a separate database query for each item. Instead, maybe change your query to do a join and include the relevant fields from the foreign table.

Anthonyh
Reply all
Reply to author
Forward
0 new messages