Hi Alessandro,
You comment was vague but led me in the right direction. Here's what I
came up with:
def checkPhone(obj):
if some regex on obj.phone:
return genshi.Markup('<a href="%s">Edit</a>' % url('/edit',
params=dict(id=obj.id)))
else:
return ''
addressbook_grid = DataGrid(fields=[
SortableColumn('Name', 'name'),
SortableColumn('Surname', 'surname'),
SortableColumn('Phone', 'phone'),
('Action', lambda obj: checkPhone(obj))
])
Works great. Thanks for the help.
Best,
Ryan
On Wednesday, October 31, 2012 6:11:55 PM UTC-4, Alessandro Molina wrote:
>
> The field callback actually receives the entire row (the obj parameter
> you see in the lambda) so you can return your content making decisions
> related to any field of the row.
>
> On Wed, Oct 31, 2012 at 10:11 PM, RyanWilson
> <[email protected]<javascript:>>
> wrote:
> > Hi,
> >
> > This is a great tutorial:
> >
> http://www.turbogears.org/2.2/docs/main/DataGrid/index.html?highlight=datagrid
>
> >
> > Can someone recommend a way to make to make the appearance 'Edit' button
> in
> > the Action column conditional on another field?
> >
> > My data table is totally different, so for example, I'd like the 'Edit'
> link
> > to only show when phone number start with '323'
> >
> > addressbook_grid = DataGrid(fields=[
> >
> > SortableColumn('Name', 'name'),
> >
> > SortableColumn('Surname', 'surname'),
> >
> > SortableColumn('Phone', 'phone'),
> >
> > ('Action', lambda obj:genshi.Markup('<a href="%s">Edit</a>' %
> > url('/edit', params=dict(item_id=obj.uid))))
> >
> > ])
> >
> >
> >
> > --
> > You received this message because you are subscribed to the Google
> Groups
> > "TurboGears" group.
> > To view this discussion on the web visit
> > https://groups.google.com/d/msg/turbogears/-/j-RfyOcCjCYJ.
> > To post to this group, send email to
> > [email protected]<javascript:>.
>
> > To unsubscribe from this group, send email to
> > [email protected] <javascript:>.
> > For more options, visit this group at
> > http://groups.google.com/group/turbogears?hl=en.
>
--
You received this message because you are subscribed to the Google Groups
"TurboGears" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/turbogears/-/00d3WuaZlYQJ.
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?hl=en.