Thanks.  Although I have to admit I don't understand why that works.  How 
does checkPhone get passed an argument?

On Friday, November 2, 2012 4:56:44 PM UTC-4, Moritz Schlarb wrote:
>
> You could also just write:
>     ('Action', checkPhone)
> instead of:
>     ('Action', lambda obj: checkPhone(obj))
>
>
> Am Donnerstag, 1. November 2012 15:29:38 UTC+1 schrieb RyanWilson:
>>
>> 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]> 
>>> 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]. 
>>> > 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. 
>>>
>>

-- 
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/-/VzRo54OjBSUJ.
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.

Reply via email to