Lasso Soft Inc. > Home

[results_navigation]

Linkresults_navigation
AuthorJason Huck
CategoryResults
Version8.x
LicensePublic Domain
Posted16 Jan 2006
Updated20 Nov 2007
More by this author...

Description

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].

Sample Usage

var('procs') = map(
	'tag_name' = { 
		local(
			'row' = params->first,
			'cell' = params->second
		);
		return('' + #cell + '');
	}
);
	
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.

	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' = '\

\ '); iterate(client_params, local('this')); if(!#this->isa('pair')); #form += '\t\n'; else((: '-skiprows') !>> #this->first); #form += '\t\n'; /if; /iterate; #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 = '< Previous  '; // #first = '<< First  '; #prev = '< Previous  '; #first = '<< First  '; /if; if(#shown_page < #skip_counts->size); // #next = '  Next >'; // #last = '  Last >>'; #next = '  Next >'; #last = '  Last >>'; /if; // generate individual page nav links iterate(#skip_counts, local('this')); if(#this >= #lower && #this <= #upper); // #display += ''; #display += ''; #shown_page == loop_count ? #display += ''; #display += loop_count; #shown_page == loop_count ? #display += ''; #display += ''; (#this < #upper && #this != #skip_counts->last) ? #display += ' | '; /if; /iterate; #out = #form + '
' + #first + #prev + #display + #next + #last + '
\n'; return(@#out); /if; /define_tag;

Related Tags

Comments

20 Nov 2007, Jason Huck

Update

Now handles single params correctly, i.e. -random (vs. -random=true).

18 Nov 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.

Please log in to comment

Subscribe to the LassoTalk mail list

LassoSoft Inc. > Home

 

 

©LassoSoft Inc 2015 | Web Development by Treefrog Inc | PrivacyLegal terms and Shipping | Contact LassoSoft