M
M
Monitorkin2017-04-10 11:12:57
Yii
Monitorkin, 2017-04-10 11:12:57

How to handle value data in GridView?

There is a loop that generates columns for the GridView:

$columns = [];
        foreach ($this->paramLabels() as $id => $label) {
            $columns[] = [
                'attribute' => "paramValues[{$id}]",
                'filter' => Html::activeTextInput($this, "paramValues[{$id}]",['class' => 'form-control']),
                'label' => $label,
                'contentOptions'=>['data-param'=>"{$id}"],
                'value' => "paramValues.{$id}.value",
            ];
        }

Further:
GridView::widget([
        'dataProvider' => $dataProvider,
        'filterModel' => $searchModel,
        'columns' => $columns,
            ]);

I don't understand how I can process 'value' by the function so that the value value is wrapped in tags for <div class="">...</div>example

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Timofeev, 2017-04-10
@Monitorkin

'value' => function($model){return '<div class="">' . $model->id . '</div>';},

only it will be necessary to 'format'=>'raw'
But maybe it's easier to add a class for the parent td?
'contentOptions'=>['data-param'=>"{$id}", 'class'=>'someClass'],

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question