karakum/yii2-grid

This package is abandoned and no longer maintained. No replacement package was suggested.

This extension provides enhanced grid view, tree grid view

Installs: 3 080

Dependents: 1

Suggesters: 0

Security: 0

Stars: 1

Watchers: 1

Forks: 0

Open Issues: 0

Type:yii2-extension

1.0.0 2016-10-19 19:39 UTC

This package is not auto-updated.

Last update: 2018-10-13 19:49:39 UTC


README

This extension inspired by leandrogehlen/yii2-treegrid but with some improves and bug fixes. TreeGridView extend yii\grid\GridView so you can use all it behaviors like column width options or filtering.

Also this extension include table-responsive-version of standard Yii2 GridView(use class \karakum\grid\GridView). To disable this feature just set 'tableWrapperOptions' => false property.

This is the jQuery TreeGrid extension for Yii 2. It encapsulates TreeGridView component in terms of Yii widgets, and thus makes using TreeGridView 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 karakum/yii2-grid "*"

or add

"karakum/yii2-grid": "*"

to the require section of your composer.json file.

How to use

Model


use yii\db\ActiveRecord;

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

    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'tree';
    }  
    
    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['name', 'description'], 'required'],
            [['name', '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,
        ]);
        $dataProvider->pagination = false;

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

View

use karakum\grid\TreeGridView;
  
<?= TreeGridView::widget([
        'dataProvider' => $dataProvider,
//        'keyColumnName' => 'id',                         // these are defaults
//        'parentColumnName' => 'parent_id',
//        'parentRootValue' => null,
        'pluginOptions' => [
			'treeColumn' => 3,                             // name
        ],
        'columns' => [
			['class' => 'yii\grid\CheckboxColumn', 'options' => ['style' => 'width: 40px;']],
			['class' => 'yii\grid\SerialColumn', 'options' => ['style' => 'width: 40px;']],
			['attribute' => 'id', 'options' => ['style' => 'width: 100px;']],
            'name',
            'description',
            'parent_id',
            ['class' => 'yii\grid\ActionColumn']
        ]     
      ]); ?>