Skip to content

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.The project was established because the original warehouse was unstable.

Notifications You must be signed in to change notification settings

hjp1011/yii2-treegrid

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

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.The project was established because the original warehouse was unstable.

Latest Stable Version Total Downloads Latest Unstable Version License PHP Version Require

Installation

The preferred way to install this extension is through composer.

Either run

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

or add

"hjp1011/yii2-treegrid": "*"

to the require section of your composer.json file.

Usage

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,
            'pagination' => false
        ]);

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

View

use yiiframe\treegrid\Auth;
  
<?= Auth::widget([
    'dataProvider' => $dataProvider,
    'keyColumnName' => 'id',
    'parentColumnName' => 'parent_id',
    'parentRootValue' => '0', //first parentId value
    'pluginOptions' => [
        'initialState' => 'collapsed',
    ],
    'columns' => [
        'name',
        'id',
        'parent_id',
        ['class' => 'yii\grid\ActionColumn']
    ]     
]); ?>

Adding resources

When is necessary to add other resource files, then should be used the Dependency Injection concept.

To use the saveState option it's necessary to add jquery.cookie.js.

//config/web.php
  
$config = [
  'id' => 'my-app',
  'components' => [
    ...
  ]
  ...
]

Yii::$container->set('yiiframe\treegrid\TreeGridAsset',[
    'js' => [
        'js/jquery.cookie.js',
        'js/jquery.treegrid.min.js',
    ]
]);

return $config;

About

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.The project was established because the original warehouse was unstable.

Resources

Stars

Watchers

Forks

Packages

No packages published