title: Yii 2.0 Gridview Toggle Data does not work when dataprovider is accessed before rendered into view
body: <p>I have configured my Gridview to export data into Excel. Additionally, I've set my page limit to 15 and currently have 80 records. </p>
  
  <p>Now, whenever I toggle the gridview to display all records for exporting, the pagination disappears but only the current items displayed on the gridview (15 items) are shown when it should be all 80. </p>
  
  <p>After playing around with my code, I found out that this occurs whenever I try to access the dataprovider in the controller before it is rendered in the view.</p>
  
  <p>Even this simple snippet in the controller causes this issue:</p>
  
  <pre><code>var_dump($dataProvider-&gt;getModels());
  </code></pre>
  
  <p>If I remove the dataprovider access, the toggle works fine. </p>
  
  <p>How can I resolve this issue? I really need to access the data inside the dataprovider to toggle my columns' visibility depending on data. before it is rendered into the view.</p>
  
  <p>I am using Kartik Gridview for Yii 2 if that means anything.</p>
  
  <p>Update: My code look something like this</p>
  
  <p><strong>Controller</strong></p>
  
  <pre><code>$model = new MyModelSearch()
  $dataProvider = $model-&gt;search(Yii::$app-&gt;request-&gt;queryParams);
  $hasTypes = ([type1 =&gt; false, type2 =&gt; false, type3 =&gt; false]);
  
  //this causes my error
  foreach($dataProvider-&gt;getModels() as $data) {
         foreach($data-&gt;myModel as $m) {
              if($hasTypes[$m-&gt;type]) {
                  continue;
                  $hasTypes[$m-&gt;type] = true;
              }
         }
  }
  return $this-&gt;render('my-view',[
        'model' =&gt; $model,
        'dataProvider' =&gt; $dataProvider,
        'hasTypes' =&gt; $hasTypes
  ]);
  </code></pre>
  
  <p><strong>View</strong></p>
  
  <pre><code>&lt;?= GridView::widget([
          'dataProvider' =&gt; $dataProvider,
          'columns' =&gt; [
                'label' =&gt; 'Type 1',
                'attribute' =&gt; 'type',
                'value' =&gt; 'type_value',
                'visible' =&gt; $hasTypes[1] // check if type is present
          ],
          'toolbar' =&gt; ['{export}', '{toggleData}'],
          'export' =&gt; ['target' =&gt; GridView::TARGET_SELF],
          'panel' =&gt; ['type' =&gt; GridView::TYPE_PRIMARY],
  ])
  </code></pre>