jeudi 7 septembre 2017

yii gridview set checkbox without $model value

I have the problem that I cant get the necessary values into the checkbox value field of my gridview. The checkboxfield can be checked or unchecked. Therfore in the database there is a boolean field called member, for datagrid values with 0 is not checked and 1 is checked.

Usually the gridview has four columns. For testing purpose I print the column 'member' of the database table in an extra field in front of the checkbox column to see whether the values of the tablecolumn 'member' are right.

Because the view has two different dataProvdiders, $dataProvider and $dataProviderMembers, I cannot use the $model object. The $model object belongs to the content of $dataProvider. The dataviewgrid will be filled by the second dataprovider $dataProviderMembers.

<?= GridView::widget([
        'dataProvider' => $dataProviderMembers,
        'columns' => [
            ['class' => 'yii\grid\SerialColumn'],
            'id',
            'firstname',
            'lastname',
            'member',
            ['class' => 'yii\grid\CheckboxColumn', 'checkboxOptions' => function($model, $key, $index, $column){
                return ['checked' => 'member'];
            }, 'header' => 'Mitglied'
            ],
            ]
    ]); ?>

With this method, the checkbox field is not filled correkt.

Normal the checkbox field will be filled by the segment

return ['checked' => $model->member};

In this case there is no $model with values for member. But I have the values for member in the $dataProviderMembers.

As I can see in the column 'member', which is before the checkbox field of the datagrid, the values from the database are right filled into the grid. How can I fill the checkbox field without $model, instead with values of the 'member' column (member values of $dataProviderMembers) of the sql query in behind? Which means something like :

return ['checked' => 'member'];




Aucun commentaire:

Enregistrer un commentaire