= TreeGrid::widget([
'dataProvider' => $dataProvider,
'keyColumnName' => 'id',
'parentColumnName' => 'pid',
'parentRootValue' => $role['id'] ?? 0, // first parentId value
'pluginOptions' => [
// 'initialState' => 'collapsed',
],
'options' => ['class' => 'table table-hover'],
'columns' => [
[
'attribute' => 'title',
'label' => '角色名称',
'format' => 'raw',
'value' => function ($model, $key, $index, $column) use ($merchant_id) {
$str = Html::tag('span', $model['title'], [
'class' => 'm-l-sm',
]);
$str .= Html::a(' ',
['edit', 'pid' => $model['id'], 'merchant_id' => $merchant_id]);
return $str;
},
],
[
'attribute' => 'sort',
'label' => '排序',
'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) use ($merchant_id, $roleIds) {
if (in_array($model['id'], $roleIds)) {
return '';
}
return Html::edit(['edit', 'id' => $model['id'], 'merchant_id' => $merchant_id]);
},
'status' => function ($url, $model, $key) use ($merchant_id, $roleIds) {
if (in_array($model['id'], $roleIds)) {
return false;
}
return Html::status($model['status']);
},
'delete' => function ($url, $model, $key) use ($merchant_id, $roleIds) {
if (in_array($model['id'], $roleIds)) {
return false;
}
return Html::delete(['delete', 'id' => $model['id'], 'merchant_id' => $merchant_id]);
},
],
],
],
]); ?>