Forum OpenACS Q&A: Problem ordering ad_table

Collapse
Posted by Nick Carroll on
Hi,

My code does not seem to be re-ordering data in a table when the table header with the sort link is selected.  I'm not sure if my table definition is correctly defined for ordering.  Any help will be much appreciated.

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.

Collapse
Posted by Andrew Piskorski on
Nick, did you look at the actual full sql query in your AOLserver log? You don't have any where clause in your query, you probably need to add one. "where 1=1" should do the trick.
Collapse
Posted by Nick Carroll on
Hi Andrew,

The sql query in the error log is as follows...

select id, summary, date from messages
where 1=1
limit 10

There seems to be no "order by" clause added to the query.

Collapse
Posted by Claudio Pasolini on
Nick, perhaps you should use the $ instead of the : notation:

[ad_order_by_from_sort_spec $orderby $table_def]

Claudio

Collapse
Posted by Jeff Davis on
Claudio is right, in your case you don't need a where clause but you do have to pass the variables into the function.  The way it's written now the literal strings ":orderby" and ":tabledef" are being passed in and of course the ad_order_by_from_sort_spec emits an empty string since it
does not have a properly structured tabledef list to work with.