Thanks to Jon's site, I also figure out how paginator works. This is a mini-how-to on how to use the paginator with ad_table (Jon's example "get_query" does not seem to work)
The following example has one flaw. To use all the options in ad_table I query the database twice. Once to get all the rows and the other to get all rows of a given page. Maybe Jon's widget will solve this problem. At the end I have also included an alternative example to ad_table.
In index.tcl, add the following lines:
set sql_select "select user_id, last_name from cc_users "
set sql_orderby " order by last_name"
set query "$sql_select $sql_orderby"
# Paginator
request create
# paginator variables
request set_param page -datatype integer -value 1
# Paginator name
set p_name "users"
#
# The create function executes the query $query and cache's the result
# For brevity I have excluded other options.
# See cms/www/modules/site-map/index.tcl for more details
#
paginator create get_objects $p_name $query -pagesize 30
# For database independence, you need to define get_objects as a fullquery in
# index-oracle.xql, and instead of $query you pass on an empty string to
# create
# Get the total number of retrieved records
set n_users [paginator get_row_count $p_name]
# Get all the ids on a page and properly quote them
set ids [paginator get_row_ids $p_name $page]
set quoted_ids [list]
foreach one_id $ids {
lappend quoted_ids "'[DoubleApos $one_id]'"
}
set userlist [join $quoted_ids ","]
# Get all the previous and next page info
paginator get_display_info $p_name info $page
# For ad_table define column lists
set table_def_users {
{last_name "Surname"}
{first_names "First Name"}
{email "Email"}
}
set query "select user_id, last_name, first_names, email from cc_users"
append query " where user_id in ($userlist) $sql_orderby"
set table_users [ad_table $query $table_def_users]
In index.adp include the following lines to navigate pages
<if @info.previous_page@ gt 0 >
<a href=index?page=@info.previous_page@>< Previous</a>
</if>
<if @page@ lt @info.page_count@>
<a href=@nextlink@&page=@info.next_page@>Next ></a>
</if>
If you are not using ad_table, then you can do the following to get to display the rows w/o a second query.
After paginator create, add to follwing line:
paginator get_data display_data $p_name items "" user_id $page
In
index-oracle.xql add
<partialquery name="display_data_partial">
<querytext>
select
user_id, last_name, first_names
from cc_users
where
-- paginator sql
user_id in (CURRENT_PAGE_SET)
</querytext>
</partialquery>
This is a must, otherwise paginator will not work. Also note that it must be a partial query tag and the name must be the get_data statement name with "_partial" appended to it.
Use multiple tags in index.adp to view page results.