PHP code example of dkhlystov / yii2-treegrid
1. Go to this page and download the library: Download dkhlystov/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/ */
dkhlystov / yii2-treegrid example snippets
<?= \dkhlystov\widgets\TreeGrid::widget([
'dataProvider' => $dataProvider,
]);
function actionIndex()
{
$dataProvider = new ActiveDataProvider([
'query' => Menu::find(),
]);
return $this->render('index', [
'dataProvider' => $dataProvider,
]);
}
<?= \dkhlystov\widgets\TreeGrid::widget([
'dataProvider' => $dataProvider,
]);
function actionIndex($id = null)
{
$initial = Menu::findOne($id);
$dataProvider = new ActiveDataProvider([
'query' => Menu::find(),
]);
return $this->render('index', [
'dataProvider' => $dataProvider,
'initial' => $initial,
]);
}
<?= \dkhlystov\widgets\TreeGrid::widget([
'dataProvider' => $dataProvider,
'initialNode' => $initial,
]);
<?= \dkhlystov\widgets\NestedTreeGrid::widget([
'dataProvider' => $dataProvider,
'moveAction' => ['move'],
]);
function actionMove($id, $target, $position)
{
$model = Menu::findOne($id);
$t = Menu::findOne($target);
switch ($position) {
case 0:
$model->insertBefore($t);
break;
case 1:
$model->appendTo($t);
break;
case 2:
$model->insertAfter($t);
break;
}
}