Search code examples
yii2

Yii2: filtering gridview from a form outside the header


Filters in the header are not friendly with mobile views. What is the best approach to remove filters in gridview's header and put them in a separated form or in a sidebar?


Solution

  • You can do this using a separated form and render it in the same view (eg: index ) you have gthe gridview .. in thi case the search model should be render by the separated form and not by the gridview ..

     <?php echo  $this->render('_search', ['model' => $searchModel]) ?>
    
     <?php 
         echo GridView::widget([
             'dataProvider' => $dataProvider,
             'columns' => [
                ['class' => 'yii\grid\SerialColumn'],
                 ......
            ]);
    
     ?>
    

    you can find a useful guide in this yii2 http://www.yiiframework.com/doc-2.0/guide-output-data-widgets.html#separate-filter-form