Forum OpenACS Q&A: ad_table, OpenACS 4 and XQL files

Collapse
Posted by Dave Bauer on
Does anyone have a working example of using ad_table and specifically
the order_by clause of ad_table to sort the columns with the query in
an XQL file?
Collapse
Posted by Ola Hansson on
Dave,

There is a good example in /packages/general-comments/www/index.tcl.

ad_table takes statement_name as parameter and sql_qry which could be the empty string, I suppose (or, rather, "SQL" to conform with Jun's new guidelines doc).

Also, the "*" after the default sort column in "{orderby {pretty_date*} }" in the declaration section of ad_page_contract is there to tell ad_table that the default sort order should be descending. Leave it out if you want ascending order. This isn't documented IIRC ...

Collapse
Posted by Dave Bauer on

I had to do the following things copied from general-comments/www/index.tcl to make it work:

Add paramter -Torderby orderby to the ad_table call. Put the table definition in a variable table_def

And add this to the end of my query in the XQL file:

[ad_order_by_from_sort_spec $orderby $table_def]
So it works, but I am not sure if there is a nicer way to make it work.
Collapse
Posted by Nick Carroll on
I can't sort items in a table either.

My sql query in my xql file looks like this...

<fullquery name="msg_sql">
  <querytext>
    select id, summary, datefrom messages
    [ad_dimensional_sql $dimensional_list limit limit]
    [ad_order_by_from_sort_spec :orderby :table_def]
  </querytext>
</fullquery>

My table_def looks like this...

set table_def {
    { id "Report" {id $order} {} }
    { summary "Summary" {summary $order} {<td> \
    <a href="summary?[export_vars -url {id}]">$summary</a></td>} c }
    { date "Date" {date $order} {} c }
}

set messages [ad_table -Torderby $orderby msg_sql {} $table_def]

And in the ad_page_contract I have declared the orderby variable as follows...

{ orderby {date} }

I think it is ordering the table based on the date column by default.

Can anyone tell me where I am going wrong with this?  I still haven't been able to sort columns by clicking on the table header.