Am Sonntag, den 03.07.2005, 09:36 +0200 schrieb Justyna:
> I need a help....I have no ideas how to sort table by table's
> heading using Z SQL Method, ZPT  and PythonScript??? I mean that I
> click on the column's header i.e. 'Name' and after this results in the
> table will be sort by name;  the same with next column -
> 'Number'. There are few examples how to make this using DTML Method,
> but I don't use DTML Method and DTML Document and it's useless for
> me... 
> I'm new in Zope and Python so I will be very very pleased for clearly
> example how can I do this!
> thanks,

I can give some hints if you want, not having the time for a complete

you can use the following ingredients:

Python Script which defines default sort order,
calls the ZSQL-method and feeds the result into


then returns the final result and the link handles to
the ZPT bei calling the ZPT with arguments, so in the
ZPT you can use option/ namespace to access them all.

from ZTUTils import make_query

# make_query() can be used to construct the query-string
# e.g. the stuff after ? on a link from complex structures
# easily: make_query(l=[{'name':'column1','sort':'asc'},
#                       {'name':'column2','sort':'desc'}])

read about the arguments to sequence.sort (some appendix
in the Zopebook, sequence is a built in module)

the idea is starting from an default sort column and order,
for every column in your result construct a new list of
column name and sort order using a simple rule:

if column name already in the list, remove it and append it
with reverse sort order.

if column name not in the list, append it with default sort

start with the list you get from request and use a default
otherwise. Copy the list when you make the column variants
and use make_query to build the query-string out of the
intermediate column specific data.

Use the query-strings with a link to the same page in 
your table heading. So each time the user clicks on 
a column header, the query-string is sent and the sort
order changed. Additionally the last sort order is
also respected.

ZPT mailing list

Reply via email to