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
use jianyan\treegrid\TreeGrid;
<?= TreeGrid::widget([
'dataProvider' => $dataProvider,
'keyColumnName' => 'id',
'parentColumnName' => 'pid',
'parentRootValue' => '0',
'pluginOptions' => [
'initialState' => 'collapsed',
'options' => ['class' => 'table table-hover'],
'columns' => [
'attribute' => 'title',
'format' => 'raw',
'value' => function ($model, $key, $index, $column){
return $model->title . Html::a(' <i class="icon ion-android-add-circle"></i>', ['ajax-edit', 'pid' => $model['id']], [
'data-toggle' => 'modal',
'data-target' => '#ajaxModal',
'attribute' => 'sort',
'format' => 'raw',
'headerOptions' => ['class' => 'col-md-1'],
'value' => function ($model, $key, $index, $column){
return Html::sort($model->sort);
'header' => "操作",
'class' => 'yii\grid\ActionColumn',
'template'=> '{edit} {status} {delete}',
'buttons' => [
'edit' => function ($url, $model, $key) {
return Html::edit(['ajax-edit','id' => $model->id], '编辑', [
'data-toggle' => 'modal',
'data-target' => '#ajaxModal',
'status' => function ($url, $model, $key) {
return Html::status($model->status);
'delete' => function ($url, $model, $key) {
return Html::delete(['delete','id' => $model->id]);
]); ?>
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。