Alberto:
> Try:
> self.param2 = XML('<span class="xy">%s</span>' % param2)
As you say, not sure if this would work, I think XML has to be called
with a kid context.
I made this work for me in two ways:
1st attempt: I altered the datagrid.kid template to check for the
presence of an xml option and used XML() if so. Ugly but it worked.
IIRC it was somthing like :
<td py:for="c in columns"
py:content="c.get_option('xml', None) and XML(c.get_field(row)) or
c.get_field(row)">
and
dg = DataGrid(fields=[('Param1', 'param1'),
DataGrid.Column('Param2', 'param2', options=dict(xml=True))])
But then I though of a better way to do it : use a widget!
Again, from memory:
def widget_getter(widget, field):
def getter(row)
return widget.display(field=getattr(row, field, ''))
return getter
class Param2Widget(Widget):
template="""<span class="xy">$field</span>"""
template_vars = ['field']
dg = DataGrid(fields=[('Param1', 'param1'),
DataGrid.Column('Param2', widget_getter(Param2Widget(),
'param2'))])
Which may be a little overkill for your simple example, but it allows
you to use arbitarily complex html within each field (eg DataGrids
within DataGrids!). I mainly wanted to use it for things like putting
links in the table cells, or displaying join column info in sum manner
(e.g. as a list (with links!))
It should be possibly to just pass a widget its self as the getter arg
to DataGrid.Column, as it is callable, but I have not got round to
having a go at that yet.
HTH
--
wavydavy
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"TurboGears" 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/turbogears
-~----------~----~----~----~------~----~------~--~---