title: Yii2: What is the correct way to include the grid-view widget in form file
body: <p>I have this code in my _form.php. The problem I am facing is if I am putting the pagination part below it does work, but filter doesn't work. If I am putting the filter part below the pagination part, the filter part work and pagination doesn't work.</p>
  
  <p>Again my netbeans IDE is complaining that I have declared the <code>$dataprovider</code> twice.</p>
  
  <p>here is my code.
  <strong>Form part:</strong></p>
  
  <pre><code>&lt;?php
  
  use yii\helpers\Html;
  use yii\widgets\ActiveForm;
  use yii\grid\GridView;
  use yii\data\ActiveDataProvider;
  use app\models\State;
  use app\models\StateSearch;
  use app\models\City;
  
  /* @var $this yii\web\View */
  /* @var $model app\models\State */
  /* @var $form yii\widgets\ActiveForm */
  
  ?&gt;
  &lt;div class="row"&gt;
      &lt;div class="col-lg-3"&gt;
  &lt;div class="col-lg-4 col-lg-offset-1"&gt;
  &lt;div class="state-form"&gt;
  
     &lt;?php $form = ActiveForm::begin(); ?&gt; 
  
      &lt;?= $form-&gt;field($model, 'state_name')-&gt;textInput(['maxlength' =&gt; 50]) ?&gt;
  
      &lt;div class="form-group"&gt;
          &lt;?= Html::submitButton($model-&gt;isNewRecord ? 'Create' : 'Update', ['class' =&gt; $model-&gt;isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?&gt;
      &lt;/div&gt;
  
      &lt;?php ActiveForm::end(); ?&gt;
  
  &lt;/div&gt;
  </code></pre>
  
  <p><strong>Pagination part</strong> </p>
  
  <pre><code>&lt;?php
      $dataProvider = new ActiveDataProvider([
          'query' =&gt; State::find(),
          'pagination' =&gt; [
              'pageSize' =&gt; 5,
          ],
      ]);
  ?&gt;
  </code></pre>
  
  <p><strong>Filter part</strong></p>
  
  <pre><code>&lt;?php  
     $searchModel = New StateSearch(); 
     $dataProvider = $searchModel-&gt;search(Yii::$app-&gt;request-&gt;queryParams);
     ?&gt;
  </code></pre>
  
  <p><strong>Gridview Widget</strong></p>
  
  <pre><code>&lt;?= GridView::widget([
          'dataProvider' =&gt; $dataProvider,
          'filterModel' =&gt; $searchModel,
  
          'columns' =&gt; [
              ['class' =&gt; 'yii\grid\SerialColumn'],
             // 'id',
              'state_name',
              ['class' =&gt; 'yii\grid\ActionColumn'],
          ],
      ]); ?&gt;   
  &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <ol>
  <li><p>What is the correct approach that my filter and pagination both works.    </p></li>
  <li><p>How to show action column icons inline(that is horizontally), I can do it at view level by setting the width, but thinking if there is a global setting for that.</p></li>
  <li><p>Can provide the pagination option on the grid-view for user selection like 5,10 or all.</p></li>
  </ol>
  
  <p>Thanks.</p>