Hello,
So I converted my results to a datagrid with sqlalchemy. Is there a way
to somehow tell datagrid to enable sorting on the results passed to it?
from turbogears.widgets import DataGrid
myusers_datagrid = DataGrid(fields=[
('DisplayedColumnName1', 'LastName'),
('DisplayedColumnName2', 'FirstName'),
]
Instructions on using datagrid with sqlalchemy.
http://lucasmanual.com/mywiki/TurboGears#head-52652ea8c6a6d23ecff0197ec6578c32415cff46
Lucas
Lukasz Szybalski wrote:
> On Jan 14, 2008 8:17 PM, W-Mark Kubacki <[EMAIL PROTECTED]> wrote:
>> Lukasz Szybalski wrote:
>>> I have a tg function that is called search. It has a widget with few
>>> text fields. I submit results to
>>>
>>> def searchresults(sefl, **kwargs)
>>> #do some selects
>>> return dict(myresults=myresults)
>>>
>>> Is there a way for me to resubmit to this function after it returned?
>>>
>>> /searchresults has my results. I want to sort them by few fields
>>>
>>> Is this possible?
>>>
>>> /searchresults/LastName
>>> or
>>> /searchresults/City
>>>
>>> If not what other options I have?
>> You can handle that this way, I assume you will order by fields of model
>> "Contact":
>>
>> def searchresults(self, *kw, **kwargs):
>> orderBy = None
>> if len(kw) > 0 and hasattr(Contact.q, kw[0]):
>> orderBy = getattr(Contact.q, kw[0])
>> # do some selects, now with orderBy=orderBy
>> return dict(myresults=myresults)
>>
>
> Assuming this function return. Now I have ordered them by Lastname let say.
> In my template there will be a link /searchresults/FirstName
>
> How will this link know the search categories? (aka **kwargs). All
> that information is in kwargs when first passed in isn't it? I don't
> see a way my link /searchresults/FirstName can sort the results I got.
>
--~--~---------~--~----~------------~-------~--~----~
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?hl=en
-~----------~----~----~----~------~----~------~--~---