Tree View

The TreeView displays hierarchical data in a tree structure. In most models you do not instantiate TreeView directly. Instead, create it via the UiBuilder API, UiBuilder.add_tree_view(), which registers the view with the UI definition and ensures it is included in the build output.

class TreeView(table, display_name=None, hidden=False)[source]

Bases: BaseTableView

A table view that supports hierarchical tree structures.

row_number_depth

The depth level at which row numbering applies.

Type:

int

dynamic_field_source

ID of the field used for determining dynamic column duplication.

Type:

Optional[str]

children_fields

List of field names used to define children at each tree level.

Type:

List[str]

table_evaluation_order

Order in which tables should be evaluated.

Type:

List[str]

__init__(table, display_name=None, hidden=False)[source]

Initializes a TreeView with support for nested children and dynamic fields.

Parameters:
  • table (Table) – The data table backing this view.

  • display_name (str | None) – Optional name to display for the view.

  • hidden (bool) – If True, the view is not visible in the UI. Defaults to False.

row_number_depth: int
dynamic_field_source: str | None
children_fields: list[str] | None
table_evaluation_order: list[str] | None
set_table_evaluation_order(*table_evaluation_order)[source]

Sets the evaluation order of tables involved in the tree.

Parameters:

table_evaluation_order (Table) – One or more tables.

Return type:

TreeView

set_children_field(*children_field)[source]

Sets the field names used to identify child relationships at each level of the hierarchy.

Each field must: - Exist in the corresponding table (table at the same index in the hierarchy). - Be of type ObjectArray. - Refer back to the correct source table.

Parameters:

*children_field (str) – One field name per hierarchy level. The number of fields must be exactly one less than the number of tables in the hierarchy.

Raises:
  • ValueError – If the number of provided field names is incorrect.

  • ValueError – If a field name does not exist in the corresponding table.

  • ValueError – If a field is not an ObjectArray type.

  • ValueError – If a field does not refer back to the correct source table.

add_field(field_id, children=None, read_only=False, allow_reset=False)[source]

Adds a tree-aware field to the view.

Parameters:
  • field_id (str) – ID of the field to add.

  • children (list[str | None] | str | None) – Child field names per hierarchy level.

  • allow_reset (bool) – If True, adds a default value reset reference to the field.

Returns:

The created tree field.

Return type:

TreeViewField

Raises:

ValueError – If the field ID does not exist in the backing table.

Supporting Types

class TreeViewField(field_id, readonly=False)[source]

Bases: ViewField

Extends ViewField to support hierarchical/tree structures.

children

Field definitions for each level of the hierarchy. A None entry means no field at that level (serialises as {"fieldId": null}).

Type:

List[str | None]

dynamic

If True, this column is dynamic and will be duplicated based on values in the deepest level of the hierarchy.

Type:

bool

default_display_value

Default value to use for dynamic columns when no row exists in the child table.

Type:

Any

override_type

Data type override for the field, if applicable.

Type:

Optional[DataType]

dynamic: bool
default_display_value: Any | None
override_type: DataType | None
set_children(children)[source]

Sets the child field names for each level of the hierarchy.

Return type:

TreeViewField

set_dynamic(dynamic)[source]

Sets whether this column is dynamic and duplicated per value in the deepest level.

Return type:

TreeViewField

set_override_type(override_type)[source]

Sets the data type override for display purposes.

Return type:

TreeViewField

set_default_display_value(value)[source]

Sets the default display value for dynamic columns when no row exists.

Return type:

TreeViewField