1. Go to this page and download the library: Download jianyan74/yii2-treegrid library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
jianyan74 / yii2-treegrid example snippets
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'], '
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
]);
}