Gridview Widget Display Boolean Column Data As Checkbox

Not a commonly question but how to do that in YII 2 ?

Thanks

Should the checkbox be active in any way or should it be just an indicator of true/false value?

If you would like to work with selected rows you may find useful a following class:


yii\grid\CheckboxColumn

Mentioned also here: http://www.yiiframework.com/doc-2.0/guide-data-grid.html#checkbox-column

If you would like the checkbox to serve only as a passive indicator you can use following column definition:


[

    'attribute' => 'foo',

    'format' => 'raw',

    'value' => function ($model, $index, $widget) {

        return Html::checkbox('foo[]', $model->foo, ['value' => $index, 'disabled' => true]);

    },

],

It’s work! You save my time !!

Thank you, best practicing

Thanks, worked. Example code with header|content class and tooltip’s


                                                    [

                                                        'label' => 'AddURL',

                                                        'format' => 'raw',

                                                        'attribute' => 'addurl',

                                                        'filter' => false,

                                                        'headerOptions' => ['class' =>

                                                            Yii::$app->user->identity->id_plan == 1 ? 'protip'

                                                                : '',

                                                            'data-pt-title' => Yii::$app->user->identity->id_plan == 1 ?

                                                                Yii::t('global', 'tooltip_tab_addurl_personal') : ''

                                                        ],

                                                        'contentOptions' => ['class' =>

                                                            Yii::$app->user->identity->id_plan == 1 ? 'protip'

                                                                : '',

                                                            'data-pt-title' => Yii::$app->user->identity->id_plan == 1 ?

                                                                Yii::t('global', 'tooltip_tab_addurl_personal') : ''

                                                        ],

                                                        'value' => function ($model, $index, $widget) {

                                                                return Html::checkbox('addurl[]', $model->addurl,

                                                                    ['value' => $index, 'disabled' => true]);

                                                        }

                                                    ],