D
D
DarkByte20152018-03-01 15:48:22
Yii
DarkByte2015, 2018-03-01 15:48:22

Why does DetailView not want to work with custom columns?

I'm trying to render a boolean field:

echo DetailView::widget([
    'model' => $model,
    'attributes' => [
        [
            'attribute' => 'is_completed',
            'class' => 'yii\grid\CheckboxColumn',
        ]
    ]
]);

But nefiga does not come out. Just the number 0/1 is displayed. What's the matter? Why does the DetailView not want to work with other column classes besides the default DataColumn?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry, 2018-03-01
@slo_nik

Good afternoon.
Why doesn't he want to. It works, it displays 0/1 for you.
What do you want to do?
Add 'value' and substitute 0 and 1
Try this.

'value' => ArrayHelper::getValue($model->attribute,[0 => 'No', 1 => 'Yes'])

V
vksee, 2018-03-02
@vksee

yii\grid\CheckboxColumn is for GridView.
Binds to rows in the table, not to a specific attribute.

Checkbox column displays the column as a checkbox...
Users can click on the checkboxes to select rows in the table.

Try this:
echo DetailView::widget([
    'model' => $model,
    'attributes' => [
        [
            'attribute' => 'is_completed',
            'format' => 'raw',
            'value' => Html::checkbox('is_completed', $model->is_completed, ['disabled'=>true])
        ]
    ]
]);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question