承接 davidxu/yii2-treegrid 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

davidxu/yii2-treegrid

最新稳定版本:2.0.0

Composer 安装命令:

composer require davidxu/yii2-treegrid

包简介

Extension for Yii2 Framework to work with jQuery TreeGrid

README 文档

README

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

Yii2 Latest Stable Version Total Downloads

Installation

The preferred way to install this extension is through composer.

Either run

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

or add

"davidxu/yii2-treegrid": "*"

to the require section of your composer.json file.

Note

For added FontAwesome 5 icons, jquery.treegrid.fa5.js source, if you are using bootstrap3, you can use jquery.treegrid.js accordingly. Details please refer to https://github.com/maxazan/jquery-treegrid.

Usage

Model

use yii\db\ActiveRecord;

/**
 * @property string $description
 * @property int $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 davidxu\treegrid\TreeGrid;
  
<?= TreeGrid::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('davidxu\treegrid\TreeGridAsset',[
    'js' => [
        'js/jquery.cookie.js',
        'js/jquery.treegrid.fa5.min.js',
    ]
]);

return $config;

统计信息

  • 总下载量: 122
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 2
  • 依赖项目数: 2
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: JavaScript

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-04-17