标题中的过滤条件与移动视图不友好。删除gridview标题中的过滤器并将它们放在单独的表单或侧边栏中的最佳方法是什么?
答案 0 :(得分:2)
您可以使用单独的表单执行此操作并在同一视图(例如:index)中将其渲染到您具有网格视图...在这种情况下,搜索模型应该由分隔的表单而不是网格视图呈现.. < / p>
<?php echo $this->render('_search', ['model' => $searchModel]) ?>
<?php
echo GridView::widget([
'dataProvider' => $dataProvider,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
......
]);
?>
您可以在此yii2 http://www.yiiframework.com/doc-2.0/guide-output-data-widgets.html#separate-filter-form
中找到有用的指南答案 1 :(得分:0)
在视图中:
<?php $form = ActiveForm::begin([
'action' => ['index'],
'method' => 'get',
]); ?>
...fields...
<?php ActiveForm::end(); ?>
<?= GridView::widget([
//...options...
]);?>
在控制器中:
$model = new Matchs();
$q = ...some empty/initial query...
if ( $model->load(Yii::$app->request->get()) ) {
$q = //...Your query with form filters...
}
$dataProvider = new ArrayDataProvider([
'key'=> 'id',
'allModels' => $q,
'sort' => ['attributes' => ['id',
'matchdate', 'schedule','teams', 'goals','comments']],
'pagination' => [
'pageSize' => 15,
],
]);
return $this->render('index', [
'dataProvider' => $dataProvider, 'model' => $model]);