Scripting Guide > Data Tables > Advanced Data Table Scripting > Add Hyperlinks to Text Columns
发布日期: 04/13/2021

Add Hyperlinks to Text Columns

You can define a text column as a column of hyperlinks using the Event Handler column property. For example, you can create a column of geographical data as hyperlinks to a Google map, or you might want to include links to a Wikipedia web pages.

Note: To learn more about the Event Handler column property, add the column property to a column that contains a hyperlink. Tips about the property are provided. To see the script that creates the property, select the data table red triangle menu; select Copy Script (No Data); and copy the script to an empty script.

Use the Event Handler column property to build hyperlinks based on one or more columns in your data table. This example shows how the hyperlinks in the SAS Offices.jmp sample data table were created.

1. Select Help > Sample Data Library and open SAS Offices.jmp.

2. Right-click the City column and select Column Info.

Notice that the Event Handler column property has been added.

3. The script on the Click tab inserts the code for the URL.

Function( {thisTable, thisColumn, iRow},
Web( "https://www.google.com/maps/@"||Char(thisTable:latitude[irow])||","||Char(thisTable:longitude[irow])||",12z" ) );

thisTable is the data table object.

thisColumn is the column object.

iRow is the index of the row in thisColumn.

Web opens the URL in the default browser.

The @ sign in "https://www.google.com/maps/@" is specific to the Google API for maps. Google expects coordinates to follow it.

||Char(thisTable:latitude[irow]) concatenates the latitude defined in the Latitude column.

||","||Char(thisTable:longitude[irow])|| concatenates the longitude defined in the Longitude column.

The Google API uses ",12z" to specify a zoom factor.

The script on the Tip tab defines the tooltip that appears when you place your cursor over the hyperlink. The tip accurately describes what happens after the link is clicked. Consider using this function to set the tooltip to the URL the Click script uses or a description of the platform.

Function( {thisTable, thisColumn, iRow},

"Open " || "https://www.google.com/maps/@"||char(thisTable:latitude[irow])||","||char(thisTable:longitude[irow])||",12z" || " in your browser.";);

Returns the tool tip string.

The script on the Color tab defines the color of the hyperlink (in this example, blue).

Function( {thisTable, thisColumn, iRow},

5;);

See JMP Colors for a diagram of JMP colors.

You might also want to embed links to other files in a data table column. The following example shows how to use Event Handler scripts and set the values to the audio and video locations on your computer.

New Table( "Wildlife",
	New Column( "Column 1", Character, "Nominal",
		Set Property( "Event Handler",
			Event Handler(
				Click( JSL Quote(Function( {thisTable, thisColumn, iRow}, Open( Char(
thisTable:thisColumn[ iRow ] ) ); );) ),
				Tip( JSL Quote(Function( {thisTable, thisColumn, iRow}, "Open " || Char(
thisTable:thisColumn[ iRow ] ) || " in a media player."; );) ),
				Color( JSL Quote(Function( {thisTable, thisColumn, iRow}, 5; );) )
			)
		),
		Set Selected,
		Set Values( {
"C:\Users\Public\Videos\Sample Videos\Wildlife.wmv",
"C:\Users\Public\Music\Sample Music\Kalimba.mp3"
		} )
	)
)

The SAS Country Office and Photo columns in SAS Offices.jmp also contain examples of Event Handler scripts.

需要更多信息?有问题?从 JMP 用户社区得到解答 (community.jmp.com).