Skip to content
Widget to display the ns tree as a grid
PHP CSS
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
assets/css
base
LICENSE
README.md
TreeView.php
composer.json

README.md

TreeView widget

Widget to display the nested sets tree as a grid

Based on GridView

Packagist Packagist Version PHP from Packagist

preview

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist koperdog/yii2-treeview "*"

or add

"koperdog/yii2-treeview": "*"

to the require section of your composer.json file.

Usage

Add to your model field:

public $children = null;

Has the same settings as GridView.

Models in dataProvider must be sorted by tree and lft

echo koperdog\yii2treeview\TreeView::widget([
	'dataProvider'  => $dataProvider,
	//'depthPrefix' => ' — ', //see Additional options
	//'depthRoot'   => 1, //see Additional options
	//'collaplse'   => true, //see Additional options
	'columns' => [
	  'id',
	  'name',
	  'created_at:datetime',
	  // ...
	],
    ]);

if you don't have column attribute name or title, for display depth use:

'columns' => [
...
[
    // your attribute options
    'value' =>  function($model, $index, $key){
    	return str_repeat('', $model->depth).$model->attribute;
    }
],
...

The column classes the same as GridView

['class' => '\koperdog\yii2treeview\base\CheckboxColumn'],
['class' => '\koperdog\yii2treeview\base\ActionColumn'],
['class' => '\koperdog\yii2treeview\base\RadioButtonColumn'],
['class' => '\koperdog\yii2treeview\base\SerialColumn'],
Additional options
depthPrefix - Prefix that displays depth (default " — ")
depthRoot - Offset from the root (default 0)
collaplse - if true, it will add the class "closed" to the node elements, and "tree-collapse" to the root of the tree (default false)
You can’t perform that action at this time.