Class kartik\tree\TreeView

Inheritancekartik\tree\TreeView » kartik\base\Widget » yii\base\Widget » yii\base\Component » yii\base\BaseObject
Implementskartik\base\BootstrapInterface, yii\base\Configurable, yii\base\ViewContextInterface
Uses Traitskartik\base\BootstrapTrait, kartik\base\TranslationTrait, kartik\base\WidgetTrait
Subclasseskartik\tree\TreeViewInput

TreeView is an enhanced tree view widget for Yii Framework 2 that allows management and manipulation of hierarchical data using nested sets. The widget utilizes the yii2-nested-sets extension to manage the tree structure in your database.

For example,

use kartik\tree\TreeView;
echo TreeView::widget([
    // single query fetch to render the tree
    'query'             => Tree::find()->addOrderBy('root, lft'),
    'headingOptions'    => ['label' => 'Categories'],
    'isAdmin'           => false,                       // optional (toggle to enable admin mode)
    'displayValue'      => 1,                           // initial display value
    //'softDelete'      => true,                        // normally not needed to change
    //'cacheSettings'   => ['enableCache' => true]      // normally not needed to change
]);

See also https://github.com/creocoder/yii2-nested-sets.

Public Properties

Hide inherited properties

PropertyTypeDescriptionDefined By
$alertFadeDuration integer Animation duration (ms) for fading in and out alerts that are displayed during manipulation of nodes. kartik\tree\TreeView
$allowNewRoots boolean Allow new root creation. kartik\tree\TreeView
$autoIdPrefix string The prefix to the automatically generated widget IDs. yii\base\Widget
$autoLoadBsPlugin boolean Whether to auto load the bootstrap plugin assets if showTooltips is true OR if TreeViewInput::asDropdown is true. kartik\tree\TreeView
$baseSourcePath string|false Get parsed base source path based on $sourcePath setting. If $sourcePath is not set, it will return the current working directory of this widget class. kartik\base\WidgetTrait
$behaviors yii\base\Behavior[] List of behaviors attached to this component. yii\base\Component
$breadcrumbs array The breadcrumbs settings for displaying the current node title based on parent hierarchy in the node details form/view (starting from the current node). kartik\tree\TreeView
$bsColCssPrefixes array The bootstrap grid column css prefixes mapping, the key is the bootstrap versions, and the value is an array containing the sizes and their corresponding grid column css prefixes. kartik\base\BootstrapTrait
$bsCssMap array CSS conversion mappings across bootstrap library versions. kartik\base\BootstrapTrait
$bsExtBasename integer The yii2 bootstrap extension base name (readonly property available via getter method getBsExtBasename()) kartik\base\BootstrapTrait
$bsVer integer Bootstrap version number currently set (readonly property available via getter method getBsVer()) kartik\base\BootstrapTrait
$bsVersion integer|string The bootstrap library version that you wish to use for this specific extension / widget. kartik\base\BootstrapTrait
$buttonGroupOptions array The HTML attributes for the button groups within the toolbar. kartik\tree\TreeView
$buttonIconOptions array The default HTML attributes for the toolbar button icons kartik\tree\TreeView
$buttonOptions array The default HTML attributes for the toolbar buttons kartik\tree\TreeView
$cacheSettings array Cache settings for displaying the detail form content for each tree node via ajax. kartik\tree\TreeView
$cascadeSelectChildren boolean Whether to auto select all children when a parent node is selected. kartik\tree\TreeView
$checkedNodeOptions array The HTML attributes for the indicator which will represent a checked checkbox. kartik\tree\TreeView
$childNodeIconOptions array The HTML attributes for the child node icon. kartik\tree\TreeView
$clientMessages array The configuration of various client alert messages kartik\tree\TreeView
$collapseNodeOptions array The HTML attributes for the indicator for collapsing a node. kartik\tree\TreeView
$counter integer A counter used to generate $id for widgets. yii\base\Widget
$defaultBtnCss string Default bootstrap button CSS (readonly property available via getter method getDefaultBtnCss()) kartik\base\BootstrapTrait
$defaultCheckedNodeIcon array Default icon for a checked node which will represent a checked checkbox. kartik\tree\TreeView
$defaultChildNodeIcon string The icon markup for the child node if no icon was setup in the database. kartik\tree\TreeView
$defaultCollapseNodeIcon string The default icon for collapsing the node. kartik\tree\TreeView
$defaultExpandNodeIcon string The default icon for expanding the node. kartik\tree\TreeView
$defaultIconPrefix string Default icon prefix (readonly property available via getter method getDefaultIconPrefix()) kartik\base\BootstrapTrait
$defaultOptions array Default HTML attributes or other settings for widgets. kartik\base\WidgetTrait
$defaultParentNodeIcon string The icon markup for the collapsed parent node if no icon was setup in the database. kartik\tree\TreeView
$defaultParentNodeOpenIcon string The icon markup for the opened parent node if no icon was setup in the database. kartik\tree\TreeView
$defaultPluginOptions array Default plugin options for the widget kartik\base\WidgetTrait
$defaultUncheckedNodeIcon string The HTML attributes for an unchecked node which will represent an unchecked checkbox. kartik\tree\TreeView
$detailOptions array The HTML attributes for the detail form container which will display the details of the selected node kartik\tree\TreeView
$displayValue integer The initial value (key) to be selected in the tree and displayed in the detail form. kartik\tree\TreeView
$dropdownClass string Bootstrap dropdown class name based on currently configured bootstrap version (readonly property available via getter method getDropdownClass()) kartik\base\BootstrapTrait
$emptyNodeMsg string Message shown on tree initialization when either the entire tree is empty or no node is found for the selected $displayValue. kartik\tree\TreeView
$emptyNodeMsgOptions array HTML attributes for the empty node message displayed. kartik\tree\TreeView
$expandNodeOptions array The HTML attributes for the indicator for expanding a node. kartik\tree\TreeView
$fontAwesome boolean Whether to use font awesome icons. kartik\tree\TreeView
$footerOptions array The HTML attributes for the tree footer container. kartik\tree\TreeView
$footerTemplate string The template for rendering the footer. kartik\tree\TreeView
$hashVarLoadPosition integer The position where the client JS hash variables for the input widget will be loaded. kartik\base\WidgetTrait
$headerOptions array The HTML attributes for the tree header container kartik\tree\TreeView
$headerTemplate string The template for rendering the header kartik\tree\TreeView
$headingOptions array The HTML attributes for the heading. kartik\tree\TreeView
$hideCssClass string The CSS class to hide HTML elements on the page. kartik\tree\TreeView
$hideTopRoot boolean Whether to hide the topmost root node container kartik\tree\TreeView
$hideUnmatchedSearchItems boolean Whether to hide unmatched search items when searching kartik\tree\TreeView
$i18n array The the internalization configuration for this widget. kartik\base\TranslationTrait
$iconEditSettings array Settings to edit the icon. kartik\tree\TreeView
$iconPrefix string The icon prefix kartik\tree\TreeView
$id string|null ID of the widget. Note that the type of this property differs in getter and setter. See getId() and setId() for details. yii\base\Widget
$isAdmin boolean Whether the tree is to be allowed for editing in admin mode. kartik\tree\TreeView
$krajeeDialogSettings array Configuration settings for the Krajee dialog widget that will be used to render alerts and confirmation dialog prompts kartik\tree\TreeView
$mainTemplate string The main template for rendering the tree view navigation widget and the node detail view form. kartik\tree\TreeView
$moduleId string The module identifier if this widget is part of a module. kartik\base\WidgetTrait
$multiple boolean Whether to allow selection of multiple nodes via checkboxes. kartik\tree\TreeView
$nodeActions array The actions for managing, deleting, and moving the tree nodes. kartik\tree\TreeView
$nodeAddlViews array The list of additional view files that will be used to append content at various sections in the $nodeView form. kartik\tree\TreeView
$nodeCheckboxOptions array The HTML attributes for the node checkbox indicator for all items in the tree kartik\tree\TreeView
$nodeFormOptions array The HTML attributes for the node detail form. kartik\tree\TreeView
$nodeLabel array|Closure The value to customize a tree node's label. kartik\tree\TreeView
$nodeTitle string The title label to display for the tree node in the validation client messages. kartik\tree\TreeView
$nodeTitlePlural string The title label to display for plural tree nodes in the validation client messages. kartik\tree\TreeView
$nodeToggleOptions array The HTML attributes for the node toggle indicator for each parent item in the tree kartik\tree\TreeView
$nodeView string The view file that will render the form for editing the node. kartik\tree\TreeView
$nodeViewButtonLabels array The markup for the submit and reset button labels in the node view form kartik\tree\TreeView
$nodeViewParams array Any additional parameters to be sent or any parameters to override within the $nodeView. kartik\tree\TreeView
$options array The HTML attributes for the input that will store the selected nodes for the widget kartik\tree\TreeView
$parentNodeIconOptions array The HTML attributes for the parent node icon. kartik\tree\TreeView
$pjaxContainerId string The identifier for the PJAX widget container if the widget is to be rendered inside a PJAX container. kartik\base\WidgetTrait
$pjaxDuplicationFix boolean Prevent duplication of pjax containers when browser back & forward buttons are pressed. kartik\base\WidgetTrait
$pluginDestroyJs string The javascript that will be used to destroy the jQuery plugin kartik\base\WidgetTrait
$pluginEvents array Widget JQuery events. kartik\base\WidgetTrait
$pluginName string The plugin name kartik\base\WidgetTrait
$pluginOptions array Widget plugin options. kartik\base\WidgetTrait
$query yii\db\ActiveQuery The query that will be used as the data source for the TreeView. kartik\tree\TreeView
$rootNodeCheckboxOptions array The HTML attributes for the root node's checkbox indicator kartik\tree\TreeView
$rootNodeToggleOptions array The HTML attributes for the root node's toggle indicator kartik\tree\TreeView
$rootOptions array The HTML attributes for the topmost root node container. kartik\tree\TreeView
$searchClearOptions array The HTML attributes for the search clear indicator kartik\tree\TreeView
$searchContainerOptions array The HTML attributes for the search container kartik\tree\TreeView
$searchOptions array The HTML attributes for the search input kartik\tree\TreeView
$showCheckbox boolean Whether to show a checkbox before each tree node label to allow multiple node selection. kartik\tree\TreeView
$showFormButtons boolean Whether to show the form action buttons in the node details form/view. kartik\tree\TreeView
$showIDAttribute boolean Whether to show the key attribute (ID) in the node details form/view. kartik\tree\TreeView
$showInactive boolean Whether to show inactive nodes kartik\tree\TreeView
$showNameAttribute boolean Whether to show the name attribute (name) in the node details form/view. kartik\tree\TreeView
$showTooltips boolean Show toolbar button tooltips (using bootstrap tooltip plugin). kartik\tree\TreeView
$softDelete boolean Whether the record will be soft deleted, when remove button is clicked. kartik\tree\TreeView
$sourcePath string Directory path to the original widget source. kartik\base\WidgetTrait
$stack yii\base\Widget[] The widgets that are currently being rendered (not ended). yii\base\Widget
$toolbar array The settings for the tree management toolbar kartik\tree\TreeView
$toolbarOptions array The HTML attributes for the toolbar. kartik\tree\TreeView
$toolbarOrder array The sorting order of the buttons in the toolbar. kartik\tree\TreeView
$topRootAsHeading boolean Whether to show topmost root node as heading. kartik\tree\TreeView
$treeOptions array The HTML attributes for the tree selector container kartik\tree\TreeView
$treeWrapperOptions array The HTML attributes for the wrapper container for the tree header, body, and footer. kartik\tree\TreeView
$uncheckedNodeOptions array The HTML attributes for the indicator which will represent an unchecked checkbox. kartik\tree\TreeView
$value string The comma separated initial value (keys) to be checked and selected in the tree kartik\tree\TreeView
$view yii\web\View The view object that can be used to render views or view files. Note that the type of this property differs in getter and setter. See getView() and setView() for details. yii\base\Widget
$viewPath string The directory containing the view files for this widget. yii\base\Widget
$wrapperTemplate string The wrapper template for rendering the tree view navigation widget. kartik\tree\TreeView

Protected Properties

Hide inherited properties

PropertyTypeDescriptionDefined By
$_bsVer integer Current bootstrap version number kartik\base\BootstrapTrait
$_dataVar string The HTML5 data variable name that will be used to store the Json encoded pluginOptions within the element on which the jQuery plugin will be initialized. kartik\base\WidgetTrait
$_defaultBtnCss string Default bootstrap button CSS kartik\base\BootstrapTrait
$_defaultIconPrefix string Default icon CSS prefix kartik\base\BootstrapTrait
$_encOptions string The JSON encoded plugin options. kartik\base\WidgetTrait
$_hasBootstrap boolean Whether to load the bootstrap plugin asset kartik\tree\TreeView
$_hashVar string The generated hashed variable name that will store the JSON encoded pluginOptions in yii\web\View::POS_HEAD. kartik\base\WidgetTrait
$_iconsListShow string The icons list show type set under iconEditSettings kartik\tree\TreeView
$_isBs4 boolean Flag to detect whether bootstrap 4. kartik\base\BootstrapTrait
$_module kartik\tree\Module The tree management module. kartik\tree\TreeView
$_msgCat string Translation message file category name for i18n. kartik\base\TranslationTrait
$_nodeIcons array Configuration of icons for Glyphicons and Font Awesome. kartik\tree\TreeView
$_nodeIconsList mixed The icons list kartik\tree\TreeView
$_nodeSelected string Session identifier for the selected node id kartik\tree\TreeView
$_nodes array The queried tree nodes kartik\tree\TreeView

Public Methods

Hide inherited methods

MethodDescriptionDefined By
__call() Calls the named method which is not a class method. yii\base\Component
__clone() This method is called after the object is created by cloning an existing one. yii\base\Component
__construct() Constructor. yii\base\BaseObject
__get() Returns the value of a component property. yii\base\Component
__isset() Checks if a property is set, i.e. defined and not null. yii\base\Component
__set() Sets the value of a component property. yii\base\Component
__unset() Sets a component property to be null. yii\base\Component
addCssClass() Adds bootstrap CSS class to options by parsing the bootstrap version for the specified Bootstrap CSS type. kartik\base\BootstrapTrait
afterRun() This method is invoked right after a widget is executed. yii\base\Widget
attachBehavior() Attaches a behavior to this component. yii\base\Component
attachBehaviors() Attaches a list of behaviors to the component. yii\base\Component
beforeRun() This method is invoked right before the widget is executed. yii\base\Widget
begin() Begins a widget. kartik\tree\TreeView
behaviors() Returns a list of behaviors that this component should behave as. yii\base\Component
canGetProperty() Returns a value indicating whether a property can be read. yii\base\Component
canSetProperty() Returns a value indicating whether a property can be set. yii\base\Component
className() Returns the fully qualified name of this class. yii\base\BaseObject
detachBehavior() Detaches a behavior from the component. yii\base\Component
detachBehaviors() Detaches all behaviors from the component. yii\base\Component
end() Ends a widget. yii\base\Widget
ensureBehaviors() Makes sure that the behaviors declared in behaviors() are attached to this component. yii\base\Component
getBSClass() Gets the respective Bootstrap class based on currently configured bootstrap version. kartik\base\BootstrapTrait
getBaseSourcePath() Get parsed base source path based on $sourcePath setting. If $sourcePath is not set, it will return the current working directory of this widget class. kartik\base\WidgetTrait
getBehavior() Returns the named behavior object. yii\base\Component
getBehaviors() Returns all behaviors attached to this component. yii\base\Component
getBsVer() Gets the current set bootstrap version number. kartik\base\BootstrapTrait
getConfig() Generates the configuration for the widget based on module level defaults kartik\tree\TreeView
getCssClass() Gets bootstrap css class by parsing the bootstrap version for the specified BS CSS type. kartik\base\BootstrapTrait
getDefaultBtnCss() Gets the default button CSS kartik\base\BootstrapTrait
getDefaultIconPrefix() Gets the default icon css prefix kartik\base\BootstrapTrait
getDropdownClass() Gets the respective bootstrap dropdown class name based on currently configured bootstrap version. kartik\base\BootstrapTrait
getId() Returns the ID of the widget. yii\base\Widget
getView() kartik\base\WidgetTrait
getViewPath() Returns the directory containing the view files for this widget. yii\base\Widget
hasEventHandlers() Returns a value indicating whether there is any handler attached to the named event. yii\base\Component
hasMethod() Returns a value indicating whether a method is defined. yii\base\Component
hasProperty() Returns a value indicating whether a property is defined for this component. yii\base\Component
init() Initializes the object. kartik\tree\TreeView
initI18N() Yii i18n messages configuration for generating translations kartik\base\TranslationTrait
initOptions() Initialize all options & settings for the widget kartik\tree\TreeView
isBs() Validate Bootstrap version kartik\base\BootstrapTrait
isBs4() Validate if Bootstrap 4.x version. kartik\base\BootstrapTrait
module() Returns the tree view module kartik\tree\TreeView
off() Detaches an existing event handler from this component. yii\base\Component
on() Attaches an event handler to an event. yii\base\Component
registerAssets() Registers the client assets for the widget kartik\tree\TreeView
registerWidgetJs() Registers a JS code block for the widget. kartik\base\WidgetTrait
removeCssClass() Removes bootstrap CSS class from options by parsing the bootstrap version for the specified Bootstrap CSS type. kartik\base\BootstrapTrait
render() Renders a view. yii\base\Widget
renderDetail() Renders the markup for the detail form to edit/view the selected tree node kartik\tree\TreeView
renderFile() Renders a view file. yii\base\Widget
renderFooter() Renders the markup for the tree footer container kartik\tree\TreeView
renderHeader() Renders the markup for the tree header container kartik\tree\TreeView
renderHeading() Renders the markup for the tree heading kartik\tree\TreeView
renderRoot() Renders the root markup for the tree kartik\tree\TreeView
renderSearch() Renders the markup for the search input kartik\tree\TreeView
renderToolbar() Renders the markup for the button actions toolbar kartik\tree\TreeView
renderTree() Renders the markup for the tree hierarchy - uses a fast non-recursive mode of tree traversal. kartik\tree\TreeView
renderWidget() Renders the widget markup kartik\tree\TreeView
renderWrapper() Renders the tree wrapper container kartik\tree\TreeView
run() Executes the widget. kartik\tree\TreeView
setId() Sets the ID of the widget. yii\base\Widget
setView() Sets the view object to be used by this widget. yii\base\Widget
trigger() Triggers an event. yii\base\Component
widget() Creates a widget instance and runs it. kartik\tree\TreeView

Protected Methods

Hide inherited methods

MethodDescriptionDefined By
addAsset() Adds an asset to the view. kartik\base\WidgetTrait
configureBsVersion() Configures the bootstrap version settings kartik\base\BootstrapTrait
fixPjaxDuplication() Fix for weird PJAX container duplication behavior on pressing browser back and forward buttons. kartik\base\WidgetTrait
getBsExtBasename() The yii2-bootstrap extension base name. kartik\base\BootstrapTrait
getIconsList() Renders the markup for the detail form to edit/view the selected tree node kartik\tree\TreeView
getPluginScript() Returns the plugin registration script. kartik\base\WidgetTrait
hashPluginOptions() Generates a hashed variable to store the pluginOptions. kartik\base\WidgetTrait
initBsVersion() Initializes bootstrap versions for the widgets and asset bundles. kartik\base\BootstrapTrait
initDestroyJs() Generates the pluginDestroyJs script if it is not set. kartik\base\WidgetTrait
initIcons() Initialize icons kartik\tree\TreeView
initSelectedNode() Initializes the selected node kartik\tree\TreeView
initTreeView() Initializes and validates the tree view configurations kartik\tree\TreeView
isSameVersion() Compares two versions and checks if they are of the same major BS version. kartik\base\BootstrapTrait
mergeDefaultOptions() Merge default options kartik\base\WidgetTrait
parseBool() Parses a boolean variable and returns as integer kartik\tree\TreeView
parseVer() Parses and returns the major BS version kartik\base\BootstrapTrait
registerPlugin() Registers a specific plugin and the related events kartik\base\WidgetTrait
registerPluginOptions() Registers plugin options by storing within a uniquely generated javascript variable. kartik\base\WidgetTrait
renderCheckboxIcon() Renders the checkbox icon markup based on fontAwesome setting kartik\tree\TreeView
renderCheckboxIconContainer() Renders the checkbox icon container kartik\tree\TreeView
renderIcon() Renders a generic icon using icon suffix kartik\tree\TreeView
renderNodeIcon() Render the default node icon markup. kartik\tree\TreeView
renderToggleIcon() Renders the default toggle icon markup based on fontAwesome setting kartik\tree\TreeView
renderToggleIconContainer() Renders the toggle icon container kartik\tree\TreeView
setDataVar() Sets a HTML5 data variable. kartik\base\WidgetTrait
sortToolbar() Sorts the toolbar based on toolbarOrder configuration kartik\tree\TreeView
usesTrait() Check if the trait is used by a specific class or recursively by any of the parent classes or parent traits kartik\tree\TreeView
validateSourceData() Validation of source query data kartik\tree\TreeView

Events

Hide inherited events

EventTypeDescriptionDefined By
EVENT_AFTER_RUN yii\base\WidgetEvent An event raised right after executing a widget. (available since version 2.0.11) yii\base\Widget
EVENT_BEFORE_RUN yii\base\WidgetEvent An event raised right before executing a widget. (available since version 2.0.11) yii\base\Widget
EVENT_INIT yii\base\Event An event that is triggered when the widget is initialized via init(). (available since version 2.0.11) yii\base\Widget

Constants

Hide inherited constants

ConstantValueDescriptionDefined By
BTN_CREATE 'create' Create tree node button kartik\tree\TreeView
BTN_CREATE_ROOT 'create-root' Create root tree node button kartik\tree\TreeView
BTN_MOVE_DOWN 'move-down' Move tree node down button kartik\tree\TreeView
BTN_MOVE_LEFT 'move-left' Move tree node left button kartik\tree\TreeView
BTN_MOVE_RIGHT 'move-right' Move tree node right button kartik\tree\TreeView
BTN_MOVE_UP 'move-up' Move tree node up button kartik\tree\TreeView
BTN_REFRESH 'refresh' Tree refresh button kartik\tree\TreeView
BTN_REMOVE 'remove' Remove tree node button kartik\tree\TreeView
BTN_SEPARATOR 'separator' Button separator kartik\tree\TreeView
ICON_CSS 1 CSS class based icon kartik\tree\TreeView
ICON_RAW 2 Raw HTML markup based icon kartik\tree\TreeView
MOVE_DOWN 'd' Direction for moving selected node DOWN one level in the tree kartik\tree\TreeView
MOVE_LEFT 'l' Direction for moving selected node LEFT one level in the tree kartik\tree\TreeView
MOVE_RIGHT 'r' Direction for moving selected node RIGHT one level in the tree kartik\tree\TreeView
MOVE_UP 'u' Direction for moving selected node UP one level in the tree kartik\tree\TreeView
ROOT_KEY 'KRAJEE~!~ROOT~!~NODE' Value for root node key kartik\tree\TreeView

Property Details

$_hasBootstrap protected property

Whether to load the bootstrap plugin asset

protected boolean $_hasBootstrap false
$_iconsListShow protected property

The icons list show type set under iconEditSettings

protected string $_iconsListShow null
$_module protected property

The tree management module.

protected kartik\tree\Module $_module null
$_nodeIcons protected static property

Configuration of icons for Glyphicons and Font Awesome. The 3rd array value is optional and includes any additional css class to be added.

protected static array $_nodeIcons = [
    'defaultExpandNodeIcon' => ['glyphicon glyphicon-expand''far fa-plus-square'], 'defaultCollapseNodeIcon' => ['glyphicon glyphicon-collapse''far fa-minus-square'], 'defaultCheckedNodeIcon' => ['glyphicon glyphicon-checked''far fa-check-square'], 'defaultUncheckedNodeIcon' => ['glyphicon glyphicon-unchecked''far fa-square'], 'defaultChildNodeIcon' => ['glyphicon glyphicon-file''fas fa-file'], 'defaultParentNodeIcon' => ['glyphicon glyphicon-folder''fas fa-folder''kv-node-closed'], 'defaultParentNodeOpenIcon' => ['glyphicon glyphicon-folder-open''fas fa-folder-open''kv-node-opened']
]
$_nodeIconsList protected property

The icons list

protected mixed $_nodeIconsList null
$_nodeSelected protected property

Session identifier for the selected node id

protected string $_nodeSelected null
$_nodes protected property

The queried tree nodes

protected array $_nodes = []
$alertFadeDuration public property

Animation duration (ms) for fading in and out alerts that are displayed during manipulation of nodes.

$allowNewRoots public property

Allow new root creation.

public boolean $allowNewRoots true
$autoLoadBsPlugin public property

Whether to auto load the bootstrap plugin assets if showTooltips is true OR if TreeViewInput::asDropdown is true. Defaults to true.

public boolean $autoLoadBsPlugin true
$breadcrumbs public property

The breadcrumbs settings for displaying the current node title based on parent hierarchy in the node details form/view (starting from the current node). The following settings are supported:

  • depth: integer, the depth to dig into the parent nodes for fetching the breadcrumb titles. If set to null or 0 this will fetch breadcrumbs till infinite parent depth. Defaults to ``.
  • glue: string, the separator to glue each node name within the breadcrumbs. Defaults to › .
  • activeCss: string, the CSS class to be applied to the current node name in the breadcrumbs. Defaults to kv-crumb-active.
  • untitled: string, the title to be displayed if this is a new untitled node record. Defaults to Untitled.
public array $breadcrumbs = []
$buttonGroupOptions public property

The HTML attributes for the button groups within the toolbar.

public array $buttonGroupOptions = [
    'class' => 'btn-group-sm'
]
$buttonIconOptions public property

The default HTML attributes for the toolbar button icons

$buttonOptions public property

The default HTML attributes for the toolbar buttons

public array $buttonOptions = []
$cacheSettings public property

Cache settings for displaying the detail form content for each tree node via ajax. The following options are supported:

  • enableCache: boolean, defaults to true.
  • cacheTimeout: integer, the cache timeout in milliseconds. Defaults to 300000 (or 5 minutes).
public array $cacheSettings = []
$cascadeSelectChildren public property

Whether to auto select all children when a parent node is selected. This property will be applied only if $multiple property is set to true.

$checkedNodeOptions public property

The HTML attributes for the indicator which will represent a checked checkbox. The following special options are recognized:

$childNodeIconOptions public property

The HTML attributes for the child node icon.

public array $childNodeIconOptions = [
    'class' => 'text-info'
]
$clientMessages public property

The configuration of various client alert messages

public array $clientMessages = []
$collapseNodeOptions public property

The HTML attributes for the indicator for collapsing a node. The following special options are recognized:

$defaultCheckedNodeIcon public property

Default icon for a checked node which will represent a checked checkbox. If not set will default to:

$defaultChildNodeIcon public property

The icon markup for the child node if no icon was setup in the database.

$defaultCollapseNodeIcon public property

The default icon for collapsing the node. If not set will default to:

$defaultExpandNodeIcon public property

The default icon for expanding the node. If not set will default to:

$defaultParentNodeIcon public property

The icon markup for the collapsed parent node if no icon was setup in the database.

$defaultParentNodeOpenIcon public property

The icon markup for the opened parent node if no icon was setup in the database. If not set will default to:

$defaultUncheckedNodeIcon public property

The HTML attributes for an unchecked node which will represent an unchecked checkbox. If not set will default to:

$detailOptions public property

The HTML attributes for the detail form container which will display the details of the selected node

public array $detailOptions = []
$displayValue public property

The initial value (key) to be selected in the tree and displayed in the detail form. Defaults to 1.

$emptyNodeMsg public property

Message shown on tree initialization when either the entire tree is empty or no node is found for the selected $displayValue.

public string $emptyNodeMsg null
$emptyNodeMsgOptions public property

HTML attributes for the empty node message displayed.

public array $emptyNodeMsgOptions = [
    'class' => 'kv-node-message'
]
$expandNodeOptions public property

The HTML attributes for the indicator for expanding a node. The following special options are recognized:

$fontAwesome public property
Deprecated since v1.1.3 (for Bootstrap 4.x and above this will always be true)

Whether to use font awesome icons. Defaults to false.

public boolean $fontAwesome false
$footerOptions public property

The HTML attributes for the tree footer container.

public array $footerOptions = []
$footerTemplate public property

The template for rendering the footer. The following tokens will be automatically parsed and replaced:

  • {toolbar}: will be replaced with the the markup for the button actions toolbar.
public string $footerTemplate "{toolbar}"
$headerOptions public property

The HTML attributes for the tree header container

public array $headerOptions = []
$headerTemplate public property

The template for rendering the header

$headingOptions public property

The HTML attributes for the heading. The following additional option is recognized: label: string, the label to display for the heading Note that when $topRootAsHeading is set to true, then $headingOptions will be entirely skipped and $rootOptions and $rootNodeToggleOptions and $rootNodeCheckboxOptions will be used to render the heading.

public array $headingOptions = [
    'class' => 'kv-tree-heading'
]
$hideCssClass public property

The CSS class to hide HTML elements on the page. If not set this will default to one of the following depending on Bootstrap Version:

  • if $bsVersion = 3, then this will default to hidden_xs
  • if $bsVersion = 4, then this will default to d-none
public string $hideCssClass null
$hideTopRoot public property

Whether to hide the topmost root node container

public boolean $hideTopRoot false
$hideUnmatchedSearchItems public property

Whether to hide unmatched search items when searching

$iconEditSettings public property

Settings to edit the icon. The following settings are recognized:

  • show: string, whether to display the icons selection as a list. If set to 'text', the icon will be shown as a plain text input along with icon type. If set to 'list', a list will be shown. If set to 'none', then no icon settings will be shown for editing.
  • type: string, the iconTypeAttribute value, defaults to TreeView::ICON_CSS. Should be one of ICON_CSS or ICON_RAW.
  • listData: array, the configuration of the icon list data to be shown for selection. This is mandatory if you set show to 'list'. You must set the data as $key => $value format. The list will be parsed to display the icon list and will depend on the type.
    • If type is set to ICON_CSS, then $key will be the icon suffix name and $value will be the description for the icon. The icon markup will be automatically parsed then based on whether its a glyphicon or font-awesome when fontAwesome property is true. For example:
           [
               'folder-close' => 'Folder',
               'file' => 'File',
               'tag' => 'Tag'
           ]
       ```
      
    • If type is set to ICON_RAW $key is the icon markup to be stored and $value is the output markup to be displayed as a selection in the list. For example:
           [
               '<img src="images/folder.jpg">' => 'Folder',
               '<img src="images/file.jpg">' => 'File',
               '<img src="images/tag.jpg">' => 'Tag',
           ]
      
public array $iconEditSettings = [
    'show' => 'text''type' => self::ICON_CSS'listData' => []]
$iconPrefix public property

The icon prefix

public string $iconPrefix null
$isAdmin public property

Whether the tree is to be allowed for editing in admin mode. This will display all nodes and will allow to modify internal tree node flags. Defaults to false.

public boolean $isAdmin false
$krajeeDialogSettings public property

Configuration settings for the Krajee dialog widget that will be used to render alerts and confirmation dialog prompts

See also http://demos.krajee.com/dialog.

$mainTemplate public property

The main template for rendering the tree view navigation widget and the node detail view form. The following tokens will be automatically parsed and replaced:

  • {wrapper}: will be replaced with the output markup parsed from $wrapperTemplate
  • {detail}: will be replaced with the the markup for the detail form to edit/view the selected tree node
$multiple public property

Whether to allow selection of multiple nodes via checkboxes.

public boolean $multiple true
$nodeActions public property

The actions for managing, deleting, and moving the tree nodes. The keys must be one of 'manage', 'save', 'remove', and 'move'. Defaults to: ` [

'save' => Url::to(['/treemanager/node/save']),
'manage' => Url::to(['/treemanager/node/manage']),
'remove' => Url::to(['/treemanager/node/remove']),
'move' => Url::to(['/treemanager/node/move']),

] `

public array $nodeActions = []
$nodeAddlViews public property

The list of additional view files that will be used to append content at various sections in the $nodeView form.

public array $nodeAddlViews = []
$nodeCheckboxOptions public property

The HTML attributes for the node checkbox indicator for all items in the tree

public array $nodeCheckboxOptions = [
    'class' => 'text-success'
]
$nodeFormOptions public property

The HTML attributes for the node detail form.

public array $nodeFormOptions = []
$nodeLabel public property

The value to customize a tree node's label.

  • if set as an array, the array key must be the node key value (i.e. keyAttribute) and array value will be the new node label you want to assign.
  • if set as a Closure, the callback function must be of the signature function($node){}, where $node will represent each tree node's model object instance. If a value is not traceable through above methods, the database tree node name will be displayed (as parsed via nameAttribute).
public array|Closure $nodeLabel null
$nodeTitle public property

The title label to display for the tree node in the validation client messages. Defaults to node.

public string $nodeTitle null
$nodeTitlePlural public property

The title label to display for plural tree nodes in the validation client messages. Defaults to nodes.

public string $nodeTitlePlural null
$nodeToggleOptions public property

The HTML attributes for the node toggle indicator for each parent item in the tree

public array $nodeToggleOptions = [
    'class' => 'text-muted'
]
$nodeView public property

The view file that will render the form for editing the node.

public string $nodeView null
$nodeViewButtonLabels public property

The markup for the submit and reset button labels in the node view form

public array $nodeViewButtonLabels = [
    'submit' => null'reset' => null
]
$nodeViewParams public property

Any additional parameters to be sent or any parameters to override within the $nodeView.

public array $nodeViewParams = []
$options public property

The HTML attributes for the input that will store the selected nodes for the widget

public array $options = []
$parentNodeIconOptions public property

The HTML attributes for the parent node icon.

public array $parentNodeIconOptions = [
    'class' => 'text-warning'
]
$query public property

The query that will be used as the data source for the TreeView. For example: Tree::find()->addOrderBy('root, lft')

public yii\db\ActiveQuery $query null
$rootNodeCheckboxOptions public property

The HTML attributes for the root node's checkbox indicator

public array $rootNodeCheckboxOptions = [
    'class' => 'text-success'
]
$rootNodeToggleOptions public property

The HTML attributes for the root node's toggle indicator

public array $rootNodeToggleOptions = [
    'class' => 'text-muted'
]
$rootOptions public property

The HTML attributes for the topmost root node container. The following special options are recognized:

  • label: string, the label for the topmost root node (this is not HTML encoded). Defaults to 'Root'. Set this to empty to not display a label.
public array $rootOptions = [
    'class' => 'text-primary'
]
$searchClearOptions public property

The HTML attributes for the search clear indicator

$searchContainerOptions public property

The HTML attributes for the search container

$searchOptions public property

The HTML attributes for the search input

public array $searchOptions = [
    'class' => 'form-control input-sm'
]
$showCheckbox public property

Whether to show a checkbox before each tree node label to allow multiple node selection.

public boolean $showCheckbox false
$showFormButtons public property

Whether to show the form action buttons in the node details form/view.

public boolean $showFormButtons true
$showIDAttribute public property

Whether to show the key attribute (ID) in the node details form/view.

public boolean $showIDAttribute true
$showInactive public property

Whether to show inactive nodes

public boolean $showInactive false
$showNameAttribute public property

Whether to show the name attribute (name) in the node details form/view.

$showTooltips public property

Show toolbar button tooltips (using bootstrap tooltip plugin). The BootstrapPluginAsset will automatically be loaded if this is set to true.

public boolean $showTooltips true
$softDelete public property

Whether the record will be soft deleted, when remove button is clicked. Defaults to true. The following actions are possible:

  • if true, this will just set the active property of node to false.
  • if false, it will attempt to hard delete the whole record.
public boolean $softDelete true
$toolbar public property

The settings for the tree management toolbar

public array $toolbar = []
$toolbarOptions public property

The HTML attributes for the toolbar.

public array $toolbarOptions = []
$toolbarOrder public property

The sorting order of the buttons in the toolbar. Each item in this array should be one of the button keys as set in the toolbar array keys (except for BTN_SEPARATOR which will be parsed as is). Note that, if this is set, then only the button keys configured here will be displayed (irrespective of the toolbar setup). Hence one must ensure that all the toolbar button keys are set here to display all the toolbar buttons.

public array $toolbarOrder = []
$topRootAsHeading public property

Whether to show topmost root node as heading. In this case the $rootOptions will be used to format the topmost root node and $headingOptions will be skipped. The CSS class kv-root-heading will be appended to rootOptions when this is set to true.

public boolean $topRootAsHeading false
$treeOptions public property

The HTML attributes for the tree selector container

public array $treeOptions = [
    'style' => 'height:410px'
]
$treeWrapperOptions public property

The HTML attributes for the wrapper container for the tree header, body, and footer.

public array $treeWrapperOptions = [
    'class' => 'form-control'
]
$uncheckedNodeOptions public property

The HTML attributes for the indicator which will represent an unchecked checkbox. The following special options are recognized:

$value public property

The comma separated initial value (keys) to be checked and selected in the tree

public string $value ''
$wrapperTemplate public property

The wrapper template for rendering the tree view navigation widget. The following tokens will be automatically parsed and replaced:

  • {header}: will be replaced with the output markup parsed from $headerTemplate.
  • {tree}: will be replaced with the markup for the tree hierarchy.
  • {footer}: will be replaced with the output markup parsed from $footerTemplate.
public string $wrapperTemplate "{header}\n{tree}{footer}"

Method Details

begin() public static method

Begins a widget.

This method creates an instance of the calling class. It will apply the configuration to the created instance. A matching end() call should be called later. As some widgets may use output buffering, the end() call should be made in the same view to avoid breaking the nesting of output buffers.

public static static begin ( $config = [] )
$config array

Name-value pairs that will be used to initialize the object properties

return static

The newly created widget instance

throws yii\base\InvalidConfigException
getConfig() public static method

Generates the configuration for the widget based on module level defaults

public static array getConfig ( $config = [] )
$config array

The widget configuration

throws yii\base\InvalidConfigException
getIconsList() protected method

Renders the markup for the detail form to edit/view the selected tree node

protected null|array getIconsList ( )
throws Exception
init() public method

Initializes the object.

This method is called at the end of the constructor. The default implementation will trigger an EVENT_INIT event.

public void init ( )
throws Exception
initIcons() protected method

Initialize icons

protected void initIcons ( )
throws \yii\base\InvalidConfigException|\Exception
initOptions() public method

Initialize all options & settings for the widget

public void initOptions ( )
throws yii\base\InvalidConfigException
initSelectedNode() protected method

Initializes the selected node

protected void initSelectedNode ( )
initTreeView() protected method

Initializes and validates the tree view configurations

protected void initTreeView ( )
throws yii\base\InvalidConfigException
module() public static method

Returns the tree view module

public static yii\base\Module module ( )
throws yii\base\InvalidConfigException
parseBool() protected static method

Parses a boolean variable and returns as integer

protected static integer parseBool ( $var )
$var boolean

The variable to parse

registerAssets() public method

Registers the client assets for the widget

public void registerAssets ( )
throws Exception
renderCheckboxIcon() protected method

Renders the checkbox icon markup based on fontAwesome setting

protected string renderCheckboxIcon ( $checked false )
$checked boolean

Whether 'checked'

renderCheckboxIconContainer() protected method

Renders the checkbox icon container

protected string renderCheckboxIconContainer ( $root false )
$root boolean

Whether its a root node

renderDetail() public method

Renders the markup for the detail form to edit/view the selected tree node

public string renderDetail ( )
throws yii\base\InvalidConfigException
renderFooter() public method

Renders the markup for the tree footer container

public string renderFooter ( )
renderHeader() public method

Renders the markup for the tree header container

public string renderHeader ( )
renderHeading() public method

Renders the markup for the tree heading

public string renderHeading ( )
renderIcon() protected method

Renders a generic icon using icon suffix

protected string renderIcon ( $icon, $options = [] )
$icon string

The icon suffix name

$options array

The HTML attributes for the icon container

renderNodeIcon() protected method

Render the default node icon markup.

protected string renderNodeIcon ( $icon, $iconType, $child true )
$icon string

The current node's icon

$iconType integer

The current node's icon type, must be one of:

  • TreeView::ICON_CSS or 1: if the icon css class suffix name is stored in $icon.
  • TreeView::ICON_RAW or 2: if the raw icon markup is stored in $icon.
$child boolean

Whether child or parent

renderRoot() public method

Renders the root markup for the tree

public string renderRoot ( )
renderSearch() public method

Renders the markup for the search input

public string renderSearch ( )
renderToggleIcon() protected method

Renders the default toggle icon markup based on fontAwesome setting

protected string renderToggleIcon ( $action 'collapse' )
$action string

Whether 'collapse' or 'expand'

renderToggleIconContainer() protected method

Renders the toggle icon container

protected string renderToggleIconContainer ( $root false )
$root boolean

Whether a root node

renderToolbar() public method

Renders the markup for the button actions toolbar

public string renderToolbar ( )
throws Exception
renderTree() public method

Renders the markup for the tree hierarchy - uses a fast non-recursive mode of tree traversal.

public string renderTree ( )
throws Exception
renderWidget() public method

Renders the widget markup

public string renderWidget ( )
throws yii\base\InvalidConfigException
renderWrapper() public method

Renders the tree wrapper container

public string renderWrapper ( )
throws Exception
run() public method

Executes the widget.

public string|void run ( )
return string|void

The rendering result may be directly "echoed" or returned as a string

throws yii\base\InvalidConfigException
sortToolbar() protected method

Sorts the toolbar based on toolbarOrder configuration

protected void sortToolbar ( )
usesTrait() protected static method

Check if the trait is used by a specific class or recursively by any of the parent classes or parent traits

protected static boolean usesTrait ( $class, $trait, $autoload false )
$class string

The class name to check

$trait string

The trait class name

$autoload boolean

Whether to autoload the class

return boolean

Whether the class has used the trait

validateSourceData() protected method

Validation of source query data

protected void validateSourceData ( )
throws yii\base\InvalidConfigException
widget() public static method

Creates a widget instance and runs it.

The widget rendering result is returned by this method.

public static string widget ( $config = [] )
$config array

Name-value pairs that will be used to initialize the object properties

return string

The rendering result of the widget.

throws Throwable