Sanjay wrote:
> I tried this:
>
> name_widget = TextField('name')
> age_widget = TextField('age')
> sortable_person_list = PaginateDataGrid(
> fields=[
> PaginateDataGrid.Column('name', name_widget, 'Name',
> options=dict(sortable=True)),
> PaginateDataGrid.Column('age', age_widget, 'Age',
> options=dict(sortable=True,
> reverse_order=True)),
> ])
>
>
> As suggested, I had added this function to the person class:
> def __str__(self):
> return self.name
>
> But then, both columns show the name only! Because, I guess, both get a
> person object and show whatever the __str__ method returns.
You'll need to wrap the widget in someting that gets the attribute you
want. Try something along the lines of:
from operator import attrgetter
def attrwidget(attr, widget):
_get_attr = attrgetter(attr)
def getter(obj):
return widget.display(_get_attr(obj))
return getter
sortable_person_list = PaginateDataGrid(
fields=[
PaginateDataGrid.Column('name',
attrwidget('name', TextField('name')),
'Name',
options=dict(sortable=True)),
PaginateDataGrid.Column('age',
attrwidget('age', TextField('age')),
'Age',
options=dict(
sortable=True,
reverse_order=True)),
])
A bit too much redundancy (specifying 'name' three times) but it does
the trick
HTH
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---