2017 © Pedro Peláez
 

yii2-extension yii2-jstree-widget

jsTree widget for yii2

image

factorenergia/yii2-jstree-widget

jsTree widget for yii2

  • Friday, April 6, 2018
  • by factorenergia
  • Repository
  • 0 Watchers
  • 0 Stars
  • 88 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 9 Forks
  • 0 Open issues
  • 15 Versions
  • 100 % Grown

The README.md

yii2-jstree-widget

Latest Stable Version Total Downloads Latest Unstable Version License, (*1)

jsTree tree widget for yii2., (*2)

Current state: WIP., (*3)

Description

This extension allows you to display and manage hierarchical data structures from your database using jsTree., (*4)

For now following data structure types are supported: - adjacency list; - nested set., (*5)

Installation

The preferred way to install this extension is through composer., (*6)

Either run, (*7)

composer require --prefer-dist factorenergia/yii2-jstree-widget "*"

or add the following to the require section of your composer.json, (*8)

"factorenergia/yii2-jstree-widget" : "*"

Usage example

For example, we have model Menu that represents our structured data. And MenuController for management purposes., (*9)

Adjacency List

In the MenuController:, (*10)

``` php use factorenergia\JsTreeWidget\actions\AdjacencyList\FullTreeDataAction; use factorenergia\JsTreeWidget\actions\AdjacencyList\TreeNodesReorderAction; use factorenergia\JsTreeWidget\actions\AdjacencyList\TreeNodeMoveAction; ... public function actions() { return [ 'getTree' => [ 'class' => FullTreeDataAction::class, 'className' => Menu::class, ], 'menuReorder' => [ 'class' => TreeNodesReorderAction::class, 'className' => Menu::class, ], 'menuChangeParent' => [ 'class' => TreeNodeMoveAction::class, 'className' => Menu::class, ], ]; }, (*11)


In your view file call the widget in the right place: ``` php <?= TreeWidget::widget([ 'treeDataRoute' => ['/menu/getTree', 'selected_id' => $parent_id], 'reorderAction' => ['/menu/menuReorder'], 'changeParentAction' => ['/menu/menuChangeParent'], 'treeType' => TreeWidget::TREE_TYPE_ADJACENCY, 'contextMenuItems' => [ 'open' => [ 'label' => 'Open', 'action' => ContextMenuHelper::actionUrl( ['/menu/list'], ['parent_id'] ), ], 'edit' => [ 'label' => 'Edit', 'action' => ContextMenuHelper::actionUrl( ['/menu/edit'] ), ] ], ]) ?>

Getting Data, Reordering and Change Parent actions has default implementations, but you can implement and use your own ones, just by changing a routes 'treeDataRoute', 'reorderAction', 'changeParentAction'., (*12)

Nested Set

Nested set can work in single or multy root modes. Single root mode by default. For using multi root mode you have to have tree (or other name you like) column in your database table to store root id. And define this name in all necessary config places (see below)., (*13)

In the MenuController:, (*14)

``` php use factorenergia\JsTreeWidget\actions\nestedset\FullTreeDataAction; use factorenergia\JsTreeWidget\actions\nestedset\NodeMoveAction; ... public function actions() { return [ 'getTree' => [ 'class' => FullTreeDataAction::class, 'className' => Menu::class, 'rootAttribute' => 'tree', //omit for single root mode ], 'treeReorder' => [ 'class' => NodeMoveAction::class, 'className' => Menu::class, 'rootAttribute' => 'tree', //omit for single root mode ], ]; }, (*15)

In the view file:
```php
    <?= TreeWidget::widget([
        'treeDataRoute' => ['/menu/getTree'],
        'reorderAction' => ['/menu/treeReorder'],
        'treeType' => TreeWidget::TREE_TYPE_NESTED_SET, //important config option
        'contextMenuItems' => [
            'edit' => [
                'label' => 'Edit',
                'action' => ContextMenuHelper::actionUrl(
                    ['/menu/edit']
                ),
            ]
        ],
    ]) ?>

Getting Data and Node Movements actions has the default implementations and are independent from side NestedSet behaviors. But you also can use your own implementation., (*16)

TreeWidget will register bundle JsTreeAssetBundle, but you may want to include it as dependency in your main bundle(ie. for minification purpose)., (*17)

ContextMenuHelper creates JsExpression for handling context menu option click. It automatically adds all data attributes from item link(<a> tag) if it is not specified exactly(as in 'open' menu item)., (*18)

The Versions

06/04 2018

dev-master

9999999-dev

jsTree widget for yii2

  Sources   Download

MIT

The Requires

 

by Evgeny Dubovitsky
by Pavel Naumov

yii2 widget tree jstree nested-sets

06/04 2018

1.3.4

1.3.4.0

jsTree widget for yii2

  Sources   Download

MIT

The Requires

 

by Evgeny Dubovitsky
by Pavel Naumov

yii2 widget tree jstree nested-sets

28/03 2018

1.3.3

1.3.3.0

jsTree widget for yii2

  Sources   Download

MIT

The Requires

 

by Evgeny Dubovitsky
by Pavel Naumov

yii2 widget tree jstree nested-sets

27/03 2018

1.3.2

1.3.2.0

jsTree widget for yii2

  Sources   Download

MIT

The Requires

 

by Evgeny Dubovitsky
by Pavel Naumov

yii2 widget tree jstree nested-sets

17/04 2017

1.3.1

1.3.1.0

jsTree widget for yii2

  Sources   Download

MIT

The Requires

 

by Evgeny Dubovitsky
by Pavel Naumov

yii2 widget tree jstree nested-sets

31/03 2017

1.3.0

1.3.0.0

jsTree widget for yii2

  Sources   Download

MIT

The Requires

 

by Evgeny Dubovitsky
by Pavel Naumov

yii2 widget tree jstree nested-sets

31/03 2017

1.2.1

1.2.1.0

jsTree widget for yii2

  Sources   Download

MIT

The Requires

 

by Evgeny Dubovitsky
by Pavel Naumov

yii2 widget tree jstree nested-sets

31/03 2017

1.2.0

1.2.0.0

jsTree widget for yii2

  Sources   Download

MIT

The Requires

 

by Evgeny Dubovitsky
by Pavel Naumov

yii2 widget tree jstree nested-sets

24/03 2017

1.1.0

1.1.0.0

jsTree widget for yii2

  Sources   Download

MIT

The Requires

 

by Evgeny Dubovitsky
by Pavel Naumov

yii2 widget tree jstree nested-sets

02/12 2016

1.0.1

1.0.1.0

jsTree widget for yii2

  Sources   Download

MIT

The Requires

 

by Evgeny Dubovitsky
by Pavel Naumov

yii2 widget tree jstree nested-sets

11/07 2016

1.0.0

1.0.0.0

jsTree widget for yii2

  Sources   Download

MIT

The Requires

 

by Evgeny Dubovitsky

yii2 widget tree jstree nested-sets

11/07 2016

dev-prerelease

dev-prerelease

jsTree widget for yii2

  Sources   Download

MIT

The Requires

 

by Evgeny Dubovitsky

yii2 widget tree jstree

11/07 2016

0.2.0

0.2.0.0

jsTree widget for yii2

  Sources   Download

MIT

The Requires

 

by Evgeny Dubovitsky

yii2 widget tree jstree

16/06 2016

dev-dev

dev-dev

jsTree widget for yii2

  Sources   Download

MIT

The Requires

 

by Evgeny Dubovitsky

yii2 widget tree jstree nested-sets

09/11 2015

0.1.0

0.1.0.0

jsTree widget for yii2

  Sources   Download

MIT

The Requires

 

by Evgeny Dubovitsky

yii2 widget tree jstree