[results_table]

Description

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

This tag is primarily designed to create quick'n'dirty results tables from within an inline, though it will work with any properly formatted data set you provide. It supports sortable columns, hidden fields, and alternating row and header styles. You can also replace the contents of any column with the result of a compound expression or tag reference. Requires [client_params]. Can be used in concert with [results_navigation] and [results_status] to put together a basic results page fairly quickly.

Parameters

-headers array, optional An array of field names to be used as table headers. Defaults to [field_names].
-data array, optional An array of arrays containing row data. Defaults to [rows_array].
-hidden array, optional An array of fields to exclude from display. The values of hidden fields are still available in each row for processes.
-procs map, optional A map of field names to compound expressions or tag references. All the field values for the current row are available to the procs as params.
-sortable boolean, optional Determines whether to make column headers sortable. Defaults to true.

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
define_tag(
		'table',
		-namespace='results_',
		-priority='replace',
		-optional='headers',
		-type='array',
		-optional='data',
		-type='array',
		-optional='hidden',
		-type='array',
		-optional='procs',
		-type='map',
		-optional='sortable',
		-type='boolean',
		-description='Generates a basic HTML results table for inlines.'
	);
		// set defaults
		!local_defined('headers') ? local('headers') = field_names;
		!local_defined('data') ? local('data') = rows_array;
		!local_defined('hidden') ? local('hidden' = array);
		!local_defined('sortable') ? local('sortable' = true);
		!local_defined('procs') ? local('procs' = map);
		
		local('out' = '\
<table width="100%" border="0" cellspacing="0" cellpadding="0">
	<tbody valign="top" class="results_table">
		<tr>
\		');
		
		iterate(#headers, local('i'));
			local('j' = #i);
			local('sortcode') = (sort_fielditem == #j ? ' id="sortcolumn"') + ' onClick="setSort(\'' + #j + '\');"';
			#hidden !>> #i ? #out += '\t\t\t<th' + (#sortable ? #sortcode) + '>' + #j->replace('_',' ')& + '</th>\n';
		/iterate;
		
		#out += '\t\t</tr>\n';

		iterate(#data, local('i'));
			#out += '\t\t<tr class="' + (loop_count % 2 == 0 ? 'rows_even' | 'rows_odd') + '">\n';
		
			iterate(#i, local('j'));
				if(#hidden !>> #headers->get(loop_count));
					#out += '\t\t\t<td>';
					
					local('proc') = #procs->find(#headers->get(loop_count));
					#out += (#proc->isa('tag') ? #proc->run( -params=array(#i,#j)) | #j);
					
					#out += '</td>\n';
				/if;
			/iterate;
			
			#out += '\t\t</tr>\n';
		/iterate;
		
		#out += '\t</tbody>\n</table>\n';

		// generate form to set sort order
		if(#sortable);
			local('form' = '\
<script language="javascript">
function setSort(column) {
	var sortCol = document.getElementById(\'sortCol\');
	var sortDir = document.getElementById(\'sortDir\');

	if(sortCol.value == column) {	
		if(sortDir.value != \'descending\') {
			sortDir.value = \'descending\';
		} else {
			sortDir.value = \'ascending\';
		}
							
		document.resultssort.submit();
	} else {
		sortCol.value = column;
		sortDir.value = \'ascending\';				
		document.resultssort.submit();
	}
}
</script>
<form name="resultssort" action="' + response_filepath + '" method="post">
	<input name="-skiprows" type="hidden" value="0">
	<input id="sortDir" type="hidden" name="sortorder" value="' + sort_orderitem + '">
	<input id="sortCol" type="hidden" name="sortfield" value="' + sort_fielditem + '">
\			');
		
			iterate(client_params, local('this'));
				if(!#this->isa('pair'));
					#form += '\t<input type="hidden" name="' + #this + '" />\n';
				else( (: 'sortfield', 'sortorder', '-skiprows') !>>  #this->first);
					#form += '\t<input type="hidden" name="' + #this->first + '" value="' + #this->second + '" />\n';
				/if;
			/iterate;
			
			#form += '</form>\n';
		
			#out += #form;
		/if;
		
		return(@#out);
	/define_tag;

 

Related Tags



Comments

05/12/2008, Asle Benoni
Re: Use other headers then field names?
I also use this with -sql inlines. Just a small example code snippet for where you put the alias would get me in the right direction :-)
05/08/2008, Jason Huck
Re: Use other headers then field names?
I'm sure this could be improved if I had the time, but I always use this with -sql inlines and simply define aliases for the column names right in the query. Works great, even with sorting.
05/08/2008, Asle Benoni
Use other headers then field names?
Hi, very nice tag that I use often to make quick results tables. Is there any way to show other headers then the field names? I.ex. the field is called "c_name" and "d_name" but I would like the header to show "Customer" and "Dealer". Some kind of map to check against? This would be a great feature :-)
11/20/2007, Jason Huck
Update
Now handles single params correctly (i.e., -random vs. -random=true).
01/21/2007, Asle Benoni
Problems sorting if ('headers') are different from field names
If 'headers' are manually defined the sorting will not work. I.ex. the fieldname is "cust_name" and one wants to display "Customer". Sorting would try to sort by "Customer" which does not exist as a field in the table. I tried to define another array with field_names but did not really get it to work. Something different must run in the "iterate(#headers, local('i'));" part I think. Glad for a simple solution!
03/17/2006, Jason Huck
Bug Fix
Fixed an issue where the tag would error if -procs were not defined.
Email:


Password:



Newest

Most Popular

Support tagSwap.net