Example 3: Complex queries

1–25 of 6,860
IDNameCodeDescriptionLatitudeLongitude
1,642 Murphy Island ISLD island 47° 17′ 23″ S 167° 29′ 24″ E
125,869 South Cape/Whiore PNT point 47° 17′ 23″ S 167° 31′ 48″ E
125,870 South West Cape/Puhiwaero PNT point 47° 16′ 48″ S 167° 27′ 36″ E
1,655 Flour Cask Bay BAY bay/inlet 47° 16′ 12″ S 167° 28′ 47″ E
1,660 Kaninihi Point PNT point 47° 16′ 12″ S 167° 34′ 11″ E
1,661 Kaninihi Island ISLD island 47° 16′ 12″ S 167° 34′ 11″ E
1,665 Wilsons Point PNT point 47° 16′ 12″ S 167° 36′ 36″ E
1,649 Poutama Passage STRA strait 47° 15′ 35″ S 167° 23′ 23″ E
1,650 Poutama Island ISLD island 47° 15′ 35″ S 167° 24′ 00″ E
1,662 Broad Bay BAY bay/inlet 47° 15′ 35″ S 167° 35′ 24″ E
1,666 Broad Head PNT point 47° 15′ 35″ S 167° 37′ 47″ E
1,648 Puwai Bay BAY bay/inlet 47° 15′ 00″ S 167° 22′ 12″ E
1,654 Nicholson Harbour BAY bay/inlet 47° 15′ 00″ S 167° 26′ 23″ E
1,663 Burial Cove BAY bay/inlet 47° 15′ 00″ S 167° 34′ 48″ E
1,643 Ernest Island ISLD island 47° 14′ 24″ S 167° 39′ 35″ E
1,651 Murderers Cove BAY bay/inlet 47° 14′ 24″ S 167° 25′ 11″ E
1,664 The Settlement BCH beach 47° 14′ 24″ S 167° 35′ 24″ E
1,667 Small Craft Retreat BAY bay/inlet 47° 14′ 24″ S 167° 39′ 00″ E
129,202 Stewart Island/Rakiura ISLD island 47° 14′ 24″ S 167° 29′ 24″ E
1,652 Patupahe Bay BAY bay/inlet 47° 13′ 47″ S 167° 25′ 48″ E
1,659 Smiths Lookout HILL hill 47° 13′ 47″ S 167° 31′ 12″ E
1,671 Nelly Island ISLD island 47° 13′ 47″ S 167° 37′ 12″ E
1,673 Sylvan Cove BAY bay/inlet 47° 13′ 47″ S 167° 33′ 00″ E
1,674 South Arm BAY bay/inlet 47° 13′ 47″ S 167° 35′ 59″ E
1,675 Disappointment Cove BAY bay/inlet 47° 13′ 47″ S 167° 36′ 36″ E
1–25 of 6,860

Sometimes a record set will need to combine data from different tables. We can implement this by creating a view in the database (example 2) or by writing the join directly within the table attribute. Here we have also added a clause to restrict the records to those below 45° south.

Features of this example:

  • The tables are joined within the table attribute, so we don't need to set up a database view.
  • A where attribute controls the subset of records to be displayed.
  • As pointdescriptioncode appears in both tables, we must qualify the column with the table name.
  • The expression attribute is used for latitude and longitude to call a user-defined function.
  • Query caching using the cachedwithin attribute.
  • The 'glacier_lavender' skin.
  • Locale-specific formatting for 'English (US)' (change this using the selector at bottom right).
Source code for this example 
<!--- 
Note that the database for this example must be set up as a datasource first. The Microsoft Access database is located in the examples folder. Place the datasource name in the request.dsn variable.

Microsoft Access is not recommended for web purposes, and is provided here for demonstration purposes only. Better performance will be achieved with enterprise databases.
--->

<cfimport prefix="esw" taglib="../customtags/eswsoftware/">

<cfif structKeyExists(url, "relatedId")>
	<cfoutput><p>Record selected: #htmlEditFormat(url.relatedId)#</p></cfoutput>
</cfif>

<esw:sortableplus 
	link="example3.cfm?relatedid=##relatedid##"
	table="namedata inner join pointdes on namedata.pointdescriptioncode = pointdes.pointdescriptioncode"
	dbms="Microsoft Access"
	datasource="#request.dsn#"
	sortBy="Latitude"
	key="relatedid"
	style="width : 600px"
	where="latitude < -45"
	cachedwithin="#createTimeSpan(0, 0, 10, 0)#"
	skin="glacier_lavender"
>

	<esw:column
		column="relatedid"
		caption="ID"
		type="numeric"
		sortDirection="asc"
	/>
	
	<esw:column
		column="pointname"
		caption="Name"
	/>
	
	<esw:column
		column="pointdes.pointdescriptioncode"
		caption="Code"
	/>
	
	<esw:column
		column="pointdescriptionname"
		caption="Description"
	/>
	
	<esw:column
		column="Latitude"
		type="numeric"
		expression="##caller.dmsFormat(latitude, 'NS')##"
	/>
	
	<esw:column
		column="Longitude"
		type="numeric"
		expression="##caller.dmsFormat(Longitude, 'EW')##"
	/>
	
</esw:sortableplus>

<cfscript>
	function dmsFormat(value) {
		var temp = abs(value);
		var d = int(temp);
		var m = 0;
		var s = 0;
		var signIndicator = arrayLen(arguments) gt 1;
		var result = "";
		temp = (temp - d) * 60;
		m = int(temp);
		temp = (temp - m) * 60;
		s = int(temp);
		result = "#d#&##176; #numberFormat(m, "00")#&##8242; #numberFormat(s, "00")#&##8243;";
		
		if ( signIndicator )
			if ( value lt 0 )
				result = result & " " & right(arguments[2],1);
			else 
				result = result & " " & left(arguments[2],1);
		else
			if ( value lt 0 )
				result = "-" & result;
		return result;
	}
</cfscript>

To run the example, you will need to:-