[Zope] sorting a table

hans hans@beehive.de
Fri, 04 Jan 2002 11:36:04 +0000


quoted manually from digest:

>MySQL, as most SQL engines has sort capabilities. I use this feature in
ZSQL
>method like this:

>Parameters :
>order mode

>ZSQL script:
>select field1, field2, field3 from mytable where (...) order by
<dtml-var
>order> <dtml-var mode>

>Pass as strings to this ZSQL method :
>order : either 'field1', 'field2', 'field3'
>mode: 'ascending' or 'descending'

>The syntax may depend on your db engine.

in DTML it looks like this for eg. sort col = FIELD:
make the column heading an URL:

  <th>
  <a href="<dtml-var document_id
                      >?col=FIELD&dir=<dtml-if "col=='TOP_NAME' and
dir=='asc'"
                                                         >desc<dtml-else

                                                         >asc</dtml-if>"

   >Topic
    <dtml-if "col=='FIELD'"><dtml-if
"dir=='asc'">V<dtml-else>A</dtml-if><dtml-else>=</dtml-if
  ></a>
  </th>