Component: Treeview

 Show all Hide all

Displays a dynamic database generated tree

Component settings

Number of visible node links
The maximum number of links to show per node. Any additional links are made available in the Navigator.
Number of visible root node links
The maximum number of links to show for the root node. Any additional links are made available in the Navigator.

SQL

SQL Call: Retrieve nodes (mandatory)

SQL to retrieve root nodes and child nodes to other nodes.
Supports custom errors: No
May modify database: No

Parameters:

@id mandatory string
id-value of the node that should be filled with child nodes, @id=NULL for the top node.

Resultset: Nodes

Resultset with the nodes to add.
Repeat mode: repeated exactly once
Row count: zero or more rows

Columns:

<column with ordinal 1> mandatory string
Contains the 'id' of the node to be added. The 'id' must be unique in the tree. This 'id' is then used when expanding/dragging/dropping the node. The 'id' value may not contain any of the following characters: ; ' "
<column with ordinal 2> mandatory string
Contains the text of the node.

If this column is named [NodeText] then the colum content is treated as plain text. If the column is named [NodeHtml] then the content is treated as HTML.
<xxx> optional string
Additional columns can be added in the resultset, these can be used for passingfields, depends_on in row-links
candrag optional bit
Determines if the node can be dragged.
Defaults to not dragable.
Possible value Description
0 Not dragable
1 Dragable
candrop optional bit
Determines if it is possible to drop other nodes on this node.
Defaults to not dropable.
Possible value Description
0 Not dropable
1 Dropable
canexpand optional bit
Determines if it is possible to expand this node.
Defaults to not expandable.
Possible value Description
0 Not expandable
1 Expandable
canreorder optional bit
Determines if this node can be reordered with drag & drop.
Defaults to not reorderable.
Possible value Description
0 Node can't be reordered
1 Node can be reordered with drag & drop
expanded optional bit
Determines whether the node starts collapsed or expanded.
Defaults to collapsed.
Possible value Description
0 Node starts collapsed
1 Node starts expanded
NodeColor optional string
Sets the text color to the specified color using #RRGGBB color code or HTML color name.
NodeStyle optional string
Sets the CSS style.
NodeTooltip optional string
Sets the tooltip.

Resultset: Root node configuration

Result set to configure the root node. Only applicable the first time when @id = NULL.
Repeat mode: repeated zero or one time
Row count: exactly one row

Columns:

<column with ordinal 1> mandatory string
Contains the 'id' of the root node. The 'id' must be unique in the tree. This 'id' is then used when dropping on the node. The 'id' value can be NULL but may not contain any of the following characters: ; ' "
<column with ordinal 2> mandatory string
Contains the text of the root node. Use NULL to keep the default of the menu item name. Styling HTML (e.g. <b> tags) is allowed.
candrop optional bit
Determines if it is possible to drop other nodes on the root node.
Defaults to not dropable.
Possible value Description
0 Not dropable
1 Dropable

SQL Call: Validate parameters

Allows you to validate the parameters supplied by the user before any other SQL is run in the component. This call is only made if the component has visible parameters, the SQL is a stored procedure, and 'Validate parameters' is checked.
Supports custom errors: No
May modify database: No

Parameters:

@force optional bit
@validateparams mandatory bit
This parameter is set to 1 by Softadmin® when this call is made.

Insert/Update/Delete SP

SQL Call: Drag & drop (mandatory)

Stored procedure run when a 'drag and drop' event occurs (only if nodes are dragable and dropable).
Supports custom errors: No
May modify database: Yes

Parameters:

@dragid mandatory string
Id of the node that initiated the drag.
@dropid mandatory string
Id of the node that drop occured on.
@droplocation optional int
In case of reorder, if the node should be inserted before (-1) or after (1) the node with id dropid.
@force optional bit
Set to '1' after 'Ok' is chosen in an ADMIN_FORCE-message

Info SQL

SQL Call: InfoSql (2008)

SQL that can have several resultsets that are displayed at top of component.
Supports custom errors: No
May modify database: No

Resultset: Main title

Specifies the main title.
Repeat mode: repeated exactly once
Row count: exactly one row

Columns:

maintitle optional string
The main title.

Resultset: Box

Defines one or more boxes to display.
Repeat mode: repeated zero or more times
Row count: one or more rows

Columns:

Title optional string
The title of the box.
TitleIconId optional int
Displays an icon next to the box title.
TitleIconBadgeId optional int
Override menuitem badge.
ColumnSpan optional int
Specifies the column span for the box. If this is above one the box will be displayed on a separate row.
LinkId optional int
Displays the specified link among the top links and in the title row of the box. The link will only appear in the title row if no ordinary columns lie before it in the resultset.

Columns named PassingField_<xxx> will not be shown in the box and can be referenced from the link as a Column value with name <xxx>.

LinkId and MenuItemId can not be used at the same time.

Multiple LinkId columns may appear in a single resultset.
MenuItemId optional int
Recomended to use LinkId instead for better tracking of links.

Displays a link to the menu item with this id among the top links and in the title row of the box. The link will only appear in the title row if no ordinary columns lie before it in the resultset.

LinkId and MenuItemId can not be used at the same time.

Multiple MenuItemId columns may appear in a single resultset.
NavigatorLinkText optional string
Used in combination with menuitemid to give the navigator link a text that differs from the name of the menu item.

If explicitly set to NULL the link will not be shown in the navigator but may still appear as a link in the title of a box.
PassingFields optional string
Additional information to 'menuitemid', appends values to querystring (supports simple Softadmin® parameters).

Multiple passingfield columns may appear in a single resultset. Passingfields will normally be connected with the closest preceeding menuitemid column, but see the note below regarding the title link.

NOTE: The first passingfield column will be used for the title link regardless of whether there is another menuitemid column in between.
<colname> optional string
Value displayed in the box with heading defined by field information or column name.
<colname>_Color optional string
Sets the text color of <colname> to the specified color using #RRGGBB color code or HTML color name.
<colname>_Icon optional string
The name of the system icon to show before the <colname> value.

Use the menu item "Admin>Theme>System icons" to register system icons.
<colname>_IconColor optional string
Color in #RRGGBB format to use for the icon specified in <colname>_Icon.
<colname>_LinkId optional int
Creates a cell link with the specified link id for the <colname> cell.

PassingField_<xxx> columns can be referenced from the link.

<colname>_LinkId and <colname>_MenuItemId can not be used at the same time.
<colname>_MenuItemId optional int
Supplies a link to the menu item with the specified menuitemid when used in conjunction with <colname>.
<colname>_PassingFields optional string
Supplies the querystring when used in conjunction with <colname>_MenuItemId.
<colname>_Style optional string
Sets the CSS style for <colname>.
<colname>_Tooltip optional string
Sets the tooltip for <colname>.
PlaintextFull, PlaintextLeft, PlaintextRight optional string
These columns are deprecated. Use either PlainText, Html or SafeHtml instead, depending on what behavior you need.

The content of this column will be treated as Html, but line breaks and non-breaking spaces will be converted to br-tags. In future versions this column will be escaped.
PlainText optional string
Displays plain text without a column title, i.e. occupies the entire vertical space available in the box. Any HTML in the text will be escaped.
Html optional string
Displays HTML without a column title, i.e. occupies the entire vertical space available in the box. Uses the Layouted HTML level to determine allowed elements and attributes.

If the Html-column is too restrictive for your needs then use the SafeHtml-column instead.
SafeHtml optional string
Displays HTML without a column title, i.e. occupies the entire vertical space available in the box. Uses the Safe HTML level to determine allowed elements and attributes.

The SafeHtml-column is less restrictive than the Html-column. Use it only when you need it.
WarningInfo optional string
The text will be at the top of the menuitem and displayed in blue.
Warning optional string
The text will be at the top of the menuitem and displayed in yellow.
WarningError optional string
The text will be at the top of the menuitem and displayed in red.
Javascript optional string
The column is hidden from the user and treated as a javascript to be included in the HTML.
StartExpanded optional bit
Whether the infobox should start expanded or collapsed. NULL/Ommited means default behavior, all expanded on big screens, only first expanded on small screens.
PassingField_<xxx> optional string
Can be used by links referenced by <colname>_LinkId or LinkId columns. Not shown in InfoSQL.
QrCode optional string
A QR Code will be rendered containing the text in the column.

Resultset: Dynamic field information

Specify extra properties for fields in the InfoSql.
Repeat mode:
Row count:

Columns:

<xxx> optional string
Set property <xxx> for the field specified in adminfieldname. If set to null the value will not be applied.
AdminFieldName mandatory string
The name of the field to apply the information to. The presence of this column indicates that the resultset specifies field information.
ButtonJavaScript<xxx> optional string
Inserts a button next to the control that is used to execute the JavaScript supplied here. <xxx> is an arbitrary text that can be empty if only one button is required.
ButtonJavaScript<xxx>_Label optional string
The label for the JavaScript button <xxx>.
CellAlignment optional string
Specifies the alignment of the text in the field.
Possible value Description
Center Center aligned.
Left Left aligned.
Right Right aligned.
ColumnTooltip optional string
Sets the tooltip on the column title. Only supported by the Grid component.
DefaultValue optional string
The default value for the control or if prefixed by 'SQL:' the sql to run to determine the default value.
Description optional string
The description for the field.
EnabledJavaScript optional string
Javascript that controls the enabled status of the field. The control is only enabled if the expression specified here evaluates to true. The expression is evaluated every time the value of a dependent control is changed. This is only available to control types for which the enabled javascript field is visible in the user interface.
FieldGroupId optional int
The field group to use.
FieldInfoId optional int
ID of field information to base the dynamic field on. All properties not explicitly overridden by dynamic field information will be copied from this field. The referenced field must be found in the menu item's field tables.
FieldLabel optional string
If present the field label is used as the heading for fields instead of the field name.
FieldType optional string
The name of the control type to use.
Height optional int
The height of the control.
IgnoreOnSave optional bit
Do not pass the field value to the insert/update procedure.
InfoSqlLayout optional string
Where the label is shown in relation to the contents in InfoSQL.
Possible value Description
LabelAbove Full width, label above.
NoLabel Full width, no label.
Standard Label to the left.
NullChoice optional bit
Specifies whether the control allows null values.
NumberOfDecimals optional int
The number of decimals to display for numeric values.
OnChangeJavaScript optional string
Javascript run when the value of the control has changed.
OutputFormat optional string
Special formatting to be applied when the field is displayed.
Possible value Description
Hyperlink
MailToLink
PhoneLink
Placeholder optional string
Text shown when the field is empty.
Sql optional string
The SQL that determines the control's behavior. (Refer to control documentation for more information)
ThousandDelimiter optional string
The thousand grouping delimiter for numeric values.
Width optional int
The width of the control.
VisibleJavaScript optional string
JavaScript that controls the visibility of the field. The control is only visible if the expression specified here evaluates to true. The expression is evaluated every time the value of a dependent control is changed.

Resultset: Dynamic top links

Defines one or more links to be shown among the top links.
Repeat mode: repeated zero or more times
Row count: zero or more rows

Columns:

LinkId optional int
See the "Box" resultset documentation.
MenuItemId mandatory int
Recomended to use LinkId instead for better tracking of links.

Displays a link to the menu item with this id among the top links. The title of the box will also turn into a link when the user hovers the mouse.
NavigatorLinkIconBadgeId optional int
Used in combination with menuitemid or LinkId to give the navigator link an icon that differs from the icon badge of the menu item.
NavigatorLinkIconId optional int
Used in combination with menuitemid or LinkId to give the navigator link an icon that differs from the icon of the menu item. Only one of navigatorlinkiconid and navigatorlinkiconname can have a value.
NavigatorLinkText optional string
Used in combination with menuitemid to give the navigator link a text that differs from the name of the menu item.
PassingField_<xxx> optional string
See the "Box" resultset documentation.
PassingFields optional string
Additional information to 'menuitemid', appends values to querystring (supports simple Softadmin® parameters).

Custom access control and logging

SQL Call: Custom access control and logging

Use this call to restrict which entries a user is allowed to view and edit, and to log which entries a user views.

Access to a menu item is normally controlled through functions and roles alone but some entities need more fine grained control. For example, a user may have access to the View Member menu item for normal members but not for members with a protected identity.

The menu items a user visits are always logged (in ADMINLogMenuItem) but for sensitive data you may need to log exactly what entries are viewed. Do the logging in this call as the common ways of viewing data (grid and InfoSQL) are not allowed to modify the database.

If you bind a scalar function instead of a stored procedure to this call then its name must end with '_GrantAccess'.
Supports custom errors: No
May modify database: Yes

Resultset: Access permissions

Return whether the user is allowed to visit the menu item with the current parameters.
Repeat mode: repeated exactly once
Row count: exactly one row

Columns:

GrantAccess mandatory bit
1 if the user is allowed to view the menu item, 0 if the user should not be allowed to view the menu item.

If 0 then an error will be logged as the user should not have been able to reach the menu item with the given parameters in the first place.

URL

Querystring parameters

menuitemheading optional
String that replaces the menu item name when the menu item is loaded. It does not replace the name before that (like for example in the navigator). It is ignored if the menu item is displayed as a part in a multipart in which case the name can be set from the multipart procedure.

Examples

Treeview procedure (hierarchical table)

Simple treeview procedure used when the database model has a straight forward child-parent structure. In the example drag and drop is supported by all nodes and reorder is not but that can easily be changed by modifying the columns [CanDrag], [CanDrop] and [CanReorder].

CREATE PROCEDURE Example.Node_TreeView
	@Id		int = null
AS
BEGIN

	------------------------------
	-- Fetch nodes for the tree --
	------------------------------

	SELECT
		-- Id and display text
		N.NodeId AS [Id],
		N.NodeName AS [NodeText],

		-- Node settings
		CONVERT(bit, 1) AS [CanDrag],
		CONVERT(bit, 1) AS [CanDrop],
		NodeInfo.CanExpand,
		CONVERT(bit, 0) AS [CanReorder],
		CONVERT(bit, 0) AS [Expanded],

		-- Passing fields
		N.NodeId,
		
		-- Dependson
		CONVERT(bit, NULL) AS [ShowSomeKindOfLink]
	FROM
		Example.Node N
		-- Check if there are child nodes
		LEFT JOIN (
			SELECT DISTINCT
				NC.NodeIdParent
			FROM
				Example.Node NC
		) Parents ON
			Parents.NodeIdParent = N.NodeId
		CROSS APPLY (
			SELECT
				CONVERT(
					bit,
					CASE
						-- Only nodes with children are expandable
						WHEN Parents.NodeIdParent IS NOT NULL THEN
							1
						ELSE
							0
					END
				) AS [CanExpand]
		) NodeInfo
	WHERE
		-- When @Id is NULL we only want nodes that have no parent
		(
			@Id IS NULL AND
			N.NodeIdParent IS NULL
		)
		OR
		N.NodeIdParent = @Id
	ORDER BY
		N.NodeName
		
	-- Defines root-node properties
	IF @Id IS null
	BEGIN
		SELECT
			null AS [Id],
			'Root' AS [NodeText],
			convert(bit, 0) AS [CanDrop]
	END

END

Treeview procedure (different kinds of nodes)

Basic treeview procedure when having a tree consisting of different kinds of nodes, say for example some kind of category at the top level and actual nodes at the other levels. Reorder is not supported.

CREATE PROCEDURE Example.Category_TreeView
	@Id		varchar(100) = null
AS
BEGIN

	----------
	-- Init --
	----------

	-- Prefixes used to distinguish the different kind of nodes
	DECLARE
		@CategoryPrefix	varchar(10)	= 'C',
		@NodePrefix		varchar(10)	= 'N'

	-- Parse relevant information from our @Id parameter
	DECLARE
		@CategoryId		int,
		@NodeIdParent	int

	-- @Id specifies a CategoryId (e.g. C7, C12, ...)
	IF @Id LIKE @CategoryPrefix + '%'
	BEGIN
		SELECT
			@CategoryId =
				-- The parameter should be NULL if nothing is specified after the prefix
				NULLIF(
					-- Remove the prefix from @Id, leaving the CategoryId
					STUFF(
						@Id,
						-- Start from the beginning of the string
						1,
						-- The number of characters to replace should be the length of the prefix
						LEN(@CategoryPrefix),
						-- Replace with the empty string
						''
					),
					''
				)
	END
	-- @Id specifies a NodeId (e.g. N17, N32, ...)
	ELSE IF @Id LIKE @NodePrefix + '%'
	BEGIN
		SELECT
			@NodeIdParent =
				-- The parameter should be NULL if nothing is specified after the prefix
				NULLIF(
					-- Remove the prefix from @Id, leaving the NodeId
					STUFF(
						@Id,
						-- Start from the beginning of the string
						1,
						-- The number of characters to replace should be the length of the prefix
						LEN(@NodePrefix),
						-- Replace with the empty string
						''
					),
					''
				)
	END

	/*
		Fetch nodes for our tree, different modes depending on the level
	*/

	----------------
	-- Root level --
	----------------

	IF @Id IS NULL
	BEGIN
		SELECT
			-- Id and display text
			@CategoryPrefix + ISNULL(CONVERT(varchar(100), C.CategoryId), '') AS [Id],
			C.CategoryName AS [NodeText],

			-- Node settings
			CONVERT(bit, 0) AS [CanDrag],
			CONVERT(bit, 1) AS [CanDrop],
			NodeInfo.CanExpand,
			CONVERT(bit, 0) AS [CanReorder],
			CONVERT(bit, 0) AS [Expanded],

			-- Passing fields
			C.CategoryId,
			CONVERT(int, NULL) AS [NodeId],
 
			-- Dependson
			CONVERT(bit, NULL) AS [ShowSomeKindOfLink]
		FROM
			Example.Category C
			-- Check if there are child nodes
			LEFT JOIN (
				SELECT DISTINCT
					N.CategoryId
				FROM
					Example.Node N
			) Parents ON
				Parents.CategoryId = C.CategoryId
			CROSS APPLY (
				SELECT
					CONVERT(
						bit,
						CASE
							-- Only nodes with children are expandable
							WHEN Parents.CategoryId IS NOT NULL THEN
								1
							ELSE
								0
						END
					) AS [CanExpand]
			) NodeInfo
		ORDER BY
			C.SortOrder

		-- Defines root-node properties
		SELECT
			null AS [Id],
			'Root' AS [NodeText],
			convert(bit, 0) AS [CanDrop]

		RETURN

	END

	------------------------------------------------------------------------------------
	-- The other levels, either nodes for a category or nodes with a specified parent --
	------------------------------------------------------------------------------------

	SELECT
		-- Id and display text
		@NodePrefix + ISNULL(CONVERT(varchar(100), N.NodeId), '') AS [Id],
		N.NodeName AS [NodeText],

		-- Node settings
		CONVERT(bit, 1) AS [CanDrag],
		CONVERT(bit, 1) AS [CanDrop],
		NodeInfo.CanExpand,
		CONVERT(bit, 0) AS [CanReorder],
		CONVERT(bit, 0) AS [Expanded],

		-- Passing fields
		CONVERT(int, NULL) AS [CategoryId],
		N.NodeId,
		
		-- Dependson
		CONVERT(bit, NULL) AS [ShowSomeKindOfLink]
	FROM
		Example.Node N
		-- Check if there are child nodes
		LEFT JOIN (
			SELECT DISTINCT
				NC.NodeIdParent
			FROM
				Example.Node NC
		) Parents ON
			Parents.NodeIdParent = N.NodeId
		CROSS APPLY (
			SELECT
				CONVERT(
					bit,
					CASE
						-- Only nodes with children are expandable
						WHEN Parents.NodeIdParent IS NOT NULL THEN
							1
						ELSE
							0
					END
				) AS [CanExpand]
		) NodeInfo
	WHERE
		-- At the next to topmost level we specify a CategoryId and want only nodes for that category
		(
			@CategoryId IS NULL
			OR
			N.CategoryId = @CategoryId
		) AND
		-- At the next to topmost level @NodeIdParent is NULL and the column should also be NULL.
		-- At the other levels we have a @NodeIdParent and want only nodes with that parent.
		(
			(
				@NodeIdParent IS NULL AND
				N.NodeIdParent IS NULL
			)
			OR
			N.NodeIdParent = @NodeIdParent
		)
	ORDER BY
		N.NodeName

END