Answer the question
In order to leave comments, you need to log in
TreeGrid how to remove and leave buttons under certain condition?
Hello everybody! I am asking this question, is it possible to somehow write a condition so that the parent category "User's workplace" has buttons as they are now, but the child categories have only deletion and editing, without an add button?
<?= TreeGrid::widget([
'columns' => [
'name',
[
'class' => 'yii\grid\ActionColumn',
'contentOptions' => ['style' => 'white-space: nowrap; text-align: center; letter-spacing: 0.1em; max-width: 7em;'],
'template' => ($data->parent_id) ? ('{add}') : ('{update} {delete} {add}'), //'{update} {delete} {add}'
'buttons' => [
'add' => function ($url, $model, $key)
{
return Html::a('<span class="glyphicon glyphicon-plus"></span>', $url);
},
]
],
],
]); ?>
Answer the question
In order to leave comments, you need to log in
Good morning.
You can try to do so. If the category does not have a parent id, then this is the parent category - the show button. If there is a parent id, that is, it is not equal to null, 0, or something else, which indicates that this is a child category - do not show the button.
'buttons' => [
'add' => function ($url, $model, $key)
{
if($model->category_id == 0){
return Html::a('<span class="glyphicon glyphicon-plus"></span>', $url);
}
},
]
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question