【发布时间】:2018-10-15 10:24:51
【问题描述】:
您好,我正在使用 yii2 Gridview,我的 gridcolumn 中有一个过滤器下拉选项,在选择下拉选项时,我的网格结果会正确更改,但我需要保留选定的下拉选项过滤器,请参阅下面的代码,
$func = Model::get_rolename();
GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchmodel,
'rowOptions' => function($model) {
return ['data-tt-id' => $model['UserId'], 'data-tt-parent-id' => $model['ManagerId']];
},
'options' => ['id' => 'sup_review'],
'columns' => [
[
'label' => 'First name',
'sortLinkOptions' => ['class' => 'desc'],
'format' => 'html',
'attribute' => 'FirstName',
'filterInputOptions' => [
'placeholder' => 'Search Name..',
'class' => 'form-control',
],
'value' => function ($model, $key, $index, $column) {
return $model['FirstName'];
},
],
[
'label' => 'Role test',
'sortLinkOptions' => ['class' => 'desc'],
'format' => 'ntext',
'attribute' => 'ClientId',
'filter' => $func,
'value' => function ($model, $key, $index, $column) {
return $model['RoleName'];
},
],
[
'label' => 'Actions',
'content' => function($model) use ($from, $to) {
return Html::a('<span class="btn btn-sm btn-primary">View</span>', Yii::$app->request->baseUrl . '/controller/function/?userid=' . $model['UserId'] . '&from=' . $from . '&to=' . $to, [
'title' => Yii::t('app', 'View'),
'data-pjax' => '0',
]);
}
],
],
]);
提前致谢:)
【问题讨论】: