Thank you Dave. I got it working. Here's how:
.tcl
ad_page_contract {
...
} {
task_revision_id:integer,optional
orderby:optional
} -properties {
...
}
...
template::list::create \
-name revisions \
-multirow revisions \
-key revision_id \
-elements {
revision_id {
label "Subject"
display_col task_title
link_url_col item_url
link_html { title "View this revision" }
display_template {<if @revisions.live_revision@ eq @revisions.revision_id@><B>@revisions.task_title@</B></if><else>@revisions.task_title@</else>}
}
description {
label "Description"
}
percent_complete {
label "Status"
display_template "@revisions.percent_complete@\%"
}
start_date {
label "Start date"
}
end_date {
label "End date"
}
} \
-orderby {
revision_id {orderby revision_id}
percent_complete {orderby percent_complete}
start_date {orderby start_date}
end_date {orderby end_date}
} \
-filters {
task_revision_id
}
if {[exists_and_not_null orderby]} {
set orderby_clause "ORDER BY [template::list::orderby_clause -name revisions]"
} else {
set orderby_clause "ORDER BY revision_id desc"
}
db_multirow -extend { item_url } revisions task_revisions_query {
} {
set item_url [export_vars -base "task-one" -override {{task_revision_id $revision_id}} -exclude {revision_id} { revision_id task_id}]
}
.xql
<fullquery name="task_revisions_query">
<querytext>
SELECT
t.item_id,
t.revision_id,
i.live_revision,
t.title as task_title,
t.description,
to_char(t.start_date,'MM/DD/YYYY') as start_date,
to_char(t.end_date,'MM/DD/YYYY') as end_date,
t.percent_complete
FROM
pm_tasks_revisionsx t, cr_items i
WHERE
t.item_id = :task_id and
t.item_id = i.item_id
$orderby_clause
</querytext>
</fullquery>
The .adp file is the same as before.
Note the use of the filters
section to make the task_revision_id be passed in when you click on the sorting links.