Reputation: 1023
I'm trying to set the header labels in a SQLFORM SmartGrid. I understand that the header argument must be a dictionary that specifies which table the setting refers to, but I'm having a hard time getting everything to line up as I would expect.
The below code uses the default header label. I've tried various combinations of headers, but am struggling to get anything to have an effect.
Model
db.define_table('parent',
Field('ParentName', type='string'),
Field('ParentDescription', type='string'),
format='%(ParentName)s'
)
db.define_table('child',
Field('ChildName', type='string'),
Field('ChildDescription', type='string'),
Field('Parent', 'reference parent')
)
Controller
def index():
grid = SQLFORM.smartgrid(db.parent,
linked_tables=['child'],
user_signature=False,
headers={'parent':{'parent.parentName':'parent'}}
)
return dict(grid=grid)
Upvotes: 0
Views: 342
Reputation: 25536
The field names are case sensitive. You have:
headers={'parent':{'parent.parentName':'parent'}}
parentName
should be ParentName
, matching the name in the field definition.
Also, an easier approach is just to specify a custom label for the field:
db.define_table('parent',
Field('ParentName', label='parent', type='string'),
...)
or dynamically in a particular context:
db.parent.ParentName.label = 'parent'
Upvotes: 2