Yii 2.0: yii2-treegrid

Extension for Yii2 Framework to work with jQuery TreeGrid
4 followers

jQuery TreeGrid Extension for Yii 2

This is the jQuery TreeGrid extension for Yii 2. It encapsulates TreeGrid component in terms of Yii widgets, and thus makes using TreeGrid component in Yii applications extremely easy.

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist leandrogehlen/yii2-treegrid "*"

or add

"leandrogehlen/yii2-treegrid": "*"

to the require section of your composer.json file.

How to use

Model

use yii\db\ActiveRecord;

/**
 * @property string $description
 * @property integer $parent_id
 */
class Tree extends ActiveRecord 
{

    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'tree';
    }  

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['description'], 'required'],
            [['description'], 'string'],
            [['parent_id'], 'integer']
        ];
    }
}

Controller

use yii\web\Controller;
use Yii;
use yii\data\ActiveDataProvider;

class TreeController extends Controller
{

    /**
     * Lists all Tree models.
     * @return mixed
     */
    public function actionIndex()
    {
        $query = Tree::find();
        $dataProvider = new ActiveDataProvider([
            'query' => $query,
        ]);

        return $this->render('index', [
            'dataProvider' => $dataProvider
        ]);
    }
}

View

  use leandrogehlen\treegrid\TreeGrid;

  <?= TreeGrid::widget([
      'dataProvider' => $dataProvider,
      'keyColumnName' => 'id',
      'parentColumnName' => 'parent_id',
      'columns' => [
          'id',
          'description',
          ['class' => 'yii\grid\ActionColumn']
      ]        
  ]); ?>

Resources

Total 4 comments

#19892 report it
des1roer at 2016/06/22 12:07pm
example

http://des1roer.blogspot.ru/2016/01/yii-2_21.html

#19600 report it
Emil Fedorciuc at 2015/09/26 04:52am
First test

Quick install, quick test, nothing rendered, I was expecting it to work out of the box. Please provide more info on how to set up and use.

#19499 report it
Kavitama at 2015/08/04 08:51pm
Examples?

Yes, please some example how to use it.

#19496 report it
skworden at 2015/08/03 11:07pm
example

Can you please post example usage?

Leave a comment

Please to leave your comment.

Create extension
Downloads
No downloadable files yet