Thursday, April 23, 2020
Tip of the Day: New TreeBuilder Plugin to Build Tree-Like
Presentations in Reports
Product.......: R:BASE X.5 and R:BASE X.5 Enterprise (Version 10.5)
Build.........: 10.5.2.20423 or higher
Sections......: Commands
Keywords......: PLUGIN, Tree Builder, Reports
Did you know there is a new internal TreeBuilder plugin to create
a "tree table", with all necessary information to build a tree-like
presentation in reports.
Syntax:
CLS
PLUGIN TreeBuilder vResult +
|TABLE TableName +
|ID IDColumn +
|PARENT ParentColumn +
|ORDER OrderColumn +
|TREE_TABLE TreeTableName
RETURN
Parameters:
. TABLE - source table
. ID - ID field in the source table
. PARENT - parent field in the source table
. ORDER - field that controls sorting (optional)
. TREE_TABLE - output table
vResult is the text variable to return the status, such as "OK"
or the exact -ERROR- message.
The created "Tree Table" output table has the following structure:
CREATE TABLE <TreeTable> +
(TREE_TABLE_ID INTEGER, +
TREE_TABLE_PARENT_ID INTEGER, +
TREE_TABLE_ROW_ID INTEGER, +
TREE_LEVEL INTEGER, +
TREE_HAS_CHILDREN INTEGER)
TREE_TABLE_ID - Incrementing integer starting with 1
TREE_TABLE_PARENT_ID - Value of the source table's parent field
TREE_TABLE_ROW_ID - Value of source table's ID field
TREE_LEVEL - The node's level. Outermost node is zero (0), then
next level is one (1), ...
TREE_HAS_CHILDREN - Indicator if node has children. One (1) if
node has children, zero (0) if no child nodes
RRBYW20 Sample:
CLS
PLUGIN TreeBuilder vResult +
|TABLE Departments +
|ID DepartmentID +
|PARENT OwnerDept +
|ORDER DepartmentID +
|TREE_TABLE DeptTree
RETURN
A view is created based on the tree output table and the source
table. The view is then used as the report's data source.
CREATE VIEW `DepartmentTree` +
(TREE_TABLE_ID,TREE_TABLE_PARENT_ID,TREE_TABLE_ROW_ID,+
TREE_LEVEL,TREE_HAS_CHILDREN,+
TREE_VEW_CAPTION,DepartmentID,Description,OwnerDept) AS +
SELECT T1.TREE_TABLE_ID,T1.TREE_TABLE_PARENT_ID, +
T1.TREE_TABLE_ROW_ID,T1.TREE_LEVEL,T1.TREE_HAS_CHILDREN,+
((SFIL(' ', T1.TREE_LEVEL*5)) + T2.Description), +
T2.DepartmentID,T2.Description,T2.OwnerDept +
FROM DeptTree T1 LEFT OUTER JOIN Departments T2 +
ON T1.TREE_TABLE_ROW_ID = T2.DepartmentID
With the following variables defined in the report expression
builder;
1 : INTEGER : D : vTreeLevel = TREE_LEVEL
2 : INTEGER : D : vHasChildren = TREE_HAS_CHILDREN
the report Detail band's "On Before Generate" EEP can use the
TREE_LEVEL and TREE_HAS_CHILDREN fields to manipulate the label
and image locations, to emulate a tree view presentation.
-- Start of EEP
-- Use TREE_LEVEL and TREE_HAS_PARENT to indent tree view
--Node label
SET VAR vMargin DOUBLE = 1.5
SET VAR vLevelIndent DOUBLE = 0.2
SET VAR vLeft = .vMargin + (.vLevelIndent * .vTreeLevel)
PROPERTY lblCaption LEFT .vLeft
--Node image. A few mms to the left of the label
SET VAR vLeft = (.vLeft - 0.3)
PROPERTY imgParent LEFT .vleft
PROPERTY imgChild LEFT .vleft
IF vHasChildren = 0 THEN
PROPERTY imgParent VISIBLE FALSE
PROPERTY imgChild VISIBLE TRUE
ELSE
PROPERTY imgParent VISIBLE TRUE
PROPERTY imgChild VISIBLE FALSE
ENDIF
RETURN
Using this approach, a tree view presentation with unlimited
node levels can be created. In addition, the tree structure
in the report can be created with very complex appearance
(e.g. a sub report inside each node). This was made possible
by the TREE_LEVEL and TREE_HAS_CHILDREN fields.
Have fun building Tree-Like Presentations in reports!
Very Best R:egards,
Razzak.
https://www.rbase.com
http://www.facebook.com/rbase/
--
For group guidelines, visit
http://www.rbase.com/support/usersgroup_guidelines.php
---
You received this message because you are subscribed to the Google Groups "RBASE-L" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/rbase-l/202004231506.03NF6ogK027310%40atl4mhob19.registeredsite.com.