Mike Coyle a écrit :

> Hi Folks,
>
> What is the preferred way to display a hyperlink within a DataGrid widget?
>
> Thanks,
>   Mike

Hello I wrote some code for testing.
BUT :
- I used DataGrigPaginate in place of simple datagrid
- I used non SQL data (sort order is not working with non SQLObject )

Finaly I don't like this way and prefere to use hand made template in
state of widget
This is only my advice.

--- here is some code from my controler ---

from elementtree import ElementTree as ET

# generate the link inside the datagrid
class MakeLink:
    def __init__(self, baseurl, id, title, action):
        self.baseurl=baseurl
        self.id=id
        self.title=title
        self.action=action

    def __call__(self, obj):
        url=controllers.url(self.baseurl,
dict(id=obj[self.id],action=self.action))
        link = ET.Element('a', href=url, style='text-decoration:
underline' )
        link.text = obj[self.title]
        return link

# to get this kind of link :
http://centos41-srv:8080/person?action=edit&id=6
mylink=MakeLink('person', 'id', 'name', 'edit')

# just to get a element from a dictionary
def get(fieldname):
    return lambda x: x.get(fieldname)

data_grid = PaginateDataGrid(
    fields = [
        PaginateDataGrid.Column(name='name', getter=mylink,
title='Name', options=dict(sortable=True)),
        PaginateDataGrid.Column(name='age', getter=get('age'),
title='Age', options=dict(sortable=True, reverse_order=True)),
    ])

class Root(controllers.RootController):
....

    # this is like paginate2 except it has sorting support
    @turbogears.expose(template='.templates.paginate2')
    @turbogears.paginate('persons', default_order='name')
    def paginate4(self):
        return dict(persons=self.persons(), list=data_grid)

    def persons(self):
        data = []
        for i in range(100):
            data.append(dict(id=i, name='name%d'%i, age=100-i))
        return data

    @turbogears.expose(template='.templates.person')
    def person(self, id, action):
        person=self.persons()[int(id)]
        return dict(person=person)

-------


--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to