[results_navigation]

Description

Link: [results_navigation]
Author: Jason Huck
Category: Results
Version: 8.x
License: Public Domain
Posted: Jan. 16, 2006
Updated: Nov. 20, 2007
More by this author...

This tag outputs "Google-style" found-set navigation, including links for first page, previous page, a user-definable range of nearby pages, next page, and last page.

It automatically includes all params passed to the current page into a form and submits to [response_filepath] via the post method so params aren't visible on the query string. Passes params called -max and -skip containing the appropriate values for -maxrecords and -skiprecords to be used in the inline that generates the results.

Output can be styled using a class called "results_navigation." Requires [client_params], available here.

Note: This tag was previously called [c5_fsnav], but was updated to use default values when available and renamed to share a common namespace with [results_table] and [results_status].

Parameters

-found integer, optional The total number of records found, typically [found_count].
-shown integer, optional Number of records per page, typically [maxrecords_value].
-skipped integer, optional Number of records skipped, typically [skiprecords_value].
-range integer, optional Number of individual page links to display. Defaults to 5, putting 2 links on either side of the current page link.
-id string, optional Unique ID to be used in resulting output.

Sample Usage

var('procs') = map(
	'tag_name' = { 
		local(
			'row' = params->first,
			'cell' = params->second
		);
		return('<a href="http://reference.omnipilot.com/LDMLReference.0.LassoApp?tag=' 
			+ #row->second + '" target="_blank">' + #cell + '</a>');
	}
);
	
var('sortCol') = (action_param('sortfield') ? action_param('sortfield') | 'ID');
var('sortDir') = (action_param('sortorder') ? action_param('sortorder') | 'ascending');
	
inline(
	-search,
	-username='xxxxxx',
	-password='xxxxxx',
	-database='LDML8_Reference',
	-table='tags',
	-returnfield='ID',
	-returnfield='tag_id',
	-returnfield='tag_name',
	-returnfield='tag_category',
	-sortfield=$sortCol,
	-sortorder=$sortDir,
	-skiprows=skiprecords_value,
	-maxrows=20
);
	results_status;

	results_table( 
		-procs=$procs,
		-hidden=array('tag_id')
	);
	
	results_navigation;
/inline;
						

Source Code

Click the "Download" button below to retrieve a copy of this tag, including the complete documentation and sample usage shown on this page. Place the downloaded ".inc" file in your LassoStartup folder, restart Lasso, and you can begin using this tag immediately.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
define_tag(
		'navigation',
		-namespace='results_',
		-opt='found', -type='integer',
		-opt='shown', -type='integer',
		-opt='skipped', -type='integer',
		-opt='range', -type='integer',		
		-opt='id', -type='string',
		-priority='replace',
		-description='Generates links for found set navigation.'
	);
		!local_defined('id') ? local('id' = lasso_uniqueid);
	
		local(
			'found_count' = (local_defined('found') ? #found | found_count),
			'shown_count' = (local_defined('shown') ? #shown | maxrecords_value),
			'shown_page' = integer,
			'skip_counts' = array,
			'skip' = (local_defined('skipped') ? #skipped | skiprecords_value),
			'counter' = 0,
			'radius' = 2,
			'display' = string,
			'prev' = string,
			'next' = string,
			'first' = string,
			'last' = string,
			'lower' = integer,
			'upper' = integer,
			'out' = string
		);

		// no navigation is needed if #found_count < #shown_count
		if(#found_count > #shown_count);
			// range defaults to 5
			!local_defined('range') ? local('range' = 5);		
			#radius = #range / 2;
		
			// generate form to preserve search params
			local('form' = '\
<script type="text/javascript">
 function setNav' + #id + '(skipNum) {
	document.getElementById(\'skip' + #id + '\').value = skipNum;
	document.getElementById(\'' + #id + '\').submit();
 }
</script>
<form action="' + response_filepath + '" method="post" id="' + #id + '">
	<input id="skip' + #id + '" type="hidden" name="-skiprows" />
\			');
			
			iterate(client_params, local('this'));
				if(!#this->isa('pair'));
					#form += '\t<input type="hidden" name="' + #this + '" />\n';
				else((: '-skiprows') !>> #this->first);
					#form += '\t<input type="hidden" name="' + #this->first + '" value="' + #this->second + '" />\n';
				/if;
			/iterate;
			
			#form += '</form>\n';
			
			// calculate number of pages
			local('pages' = #found_count / #shown_count);	
			#found_count % #shown_count > 0 ? #pages += 1;
			
			// calculate skip count for each page
			loop(#pages);
				#skip_counts->insert(#counter);
				#counter += #shown_count;
			/loop;
			
			// find the current page
			#shown_page = #skip_counts->findposition(#skip)->get(1);
	
			// determine range of pages to show
			#lower = #skip - (#shown_count * #radius);
			#upper = #skip + (#shown_count * #radius);
		
			// find previous/next, first/last links
			if(#shown_page > 1);
				// #prev = '<a href="#" onClick="setNav' + #id + '(' + (#skip - #shown_count) + ');">< Previous</a>  ';
				// #first = '<a href="#" onClick="setNav' + #id + '(0);"><< First</a>  ';		
				#prev = '<a href="javascript:setNav' + #id + '(' + (#skip - #shown_count) + ');">< Previous</a>  ';
				#first = '<a href="javascript:setNav' + #id + '(0);"><< First</a>  ';		
			/if;
			
			if(#shown_page < #skip_counts->size);
				// #next = '  <a href="#" onClick="setNav' + #id + '(' + (#skip + #shown_count) + ');">Next ></a>';
				// #last = '  <a href="#" onClick="setNav' + #id + '(' + #skip_counts->last + ');">Last >></a>';
				#next = '  <a href="javascript:setNav' + #id + '(' + (#skip + #shown_count) + ');">Next ></a>';
				#last = '  <a href="javascript:setNav' + #id + '(' + #skip_counts->last + ');">Last >></a>';
			/if;
				
			// generate individual page nav links
			iterate(#skip_counts, local('this'));
				if(#this >= #lower && #this <= #upper);
					// #display += '<a href="#" onClick="setNav' + #id + '(' + #this + ');">';		
					#display += '<a href="javascript:setNav' + #id + '(' + #this + ');">';		
					#shown_page == loop_count ? #display += '<strong>';
					#display += loop_count;
					#shown_page == loop_count ? #display += '</strong>';	
					#display += '</a>';			
					(#this < #upper && #this != #skip_counts->last) ? #display += ' | ';
				/if;
			/iterate;
			
			#out = #form + '<div class="results_navigation">' + #first + #prev + #display + #next + #last + '</div>\n';
			
			return(@#out);
		/if;
	/define_tag;

 

Related Tags



Comments

11/20/2007, Jason Huck
Update
Now handles single params correctly, i.e. -random (vs. -random=true).
11/18/2006, Jason Huck
Update
Added a unique ID to the generated javascript and HTML so that you can use multiple instances of the tag on the same page. Thanks to Randy Phillips for the suggestion.
Email:


Password:



Newest

Most Popular