Yii2 kartik grid export all columns
<p>I am using kartik grid and want to export all columns present in my table.</p>

<p>Problem is that i want to show only few columns in grid but download all columns in csv file.</p>

<p>Is it possible?</p>

<p>My code</p>

<pre><code>&lt;?php  

$gridColumns = [
    ['class' =&gt; 'kartik\grid\SerialColumn'],
    [
        'class' =&gt; 'kartik\grid\EditableColumn',
        'attribute' =&gt; 'Name',        
        'vAlign'=&gt;'middle',
        'headerOptions'=&gt;['class'=&gt;'kv-sticky-column'],
        'contentOptions'=&gt;['class'=&gt;'kv-sticky-column'],
        'editableOptions'=&gt;['header'=&gt;'Name', 'size'=&gt;'255'],
        'format'=&gt;'text',
    ],
    [

        'attribute' =&gt; 'Description',        
        'vAlign'=&gt;'middle',
        'headerOptions'=&gt;['class'=&gt;'kv-sticky-column'],
        'contentOptions'=&gt;['class'=&gt;'kv-sticky-column'],     
        'format'=&gt;'text',
    ],
    ['class' =&gt; 'kartik\grid\DataColumn',
        'attribute' =&gt; 'image',
        'format' =&gt; 'html',
        'value' =&gt; function($model, $key, $index, $column) {          
              return Html::img('http://localhost/demo/basic_demo/web/www/img/'.$model-&gt;image, ['class' =&gt; 'abc','width'=&gt;70,'height'=&gt;70]);          
        },
   ],
    [
        'class'=&gt;'kartik\grid\BooleanColumn',
        'attribute'=&gt;'Status', 
        'vAlign'=&gt;'middle',
    ],

    [
        'class' =&gt; 'kartik\grid\ActionColumn',
        'dropdown' =&gt; true,
        'vAlign'=&gt;'middle',    
        'viewOptions'=&gt;['title'=&gt;'viewMsg', 'data-toggle'=&gt;'tooltip'],
        'updateOptions'=&gt;['title'=&gt;'updateMsg', 'data-toggle'=&gt;'tooltip'],
        'deleteOptions'=&gt;['title'=&gt;'deleteMsg', 'data-toggle'=&gt;'tooltip'], 

     ],
     [
          'class' =&gt; '\kartik\grid\ExpandRowColumn',
          'header' =&gt; '',
               'value' =&gt; function ($model, $key, $index) { 
               return GridView::ROW_COLLAPSED;
          },
          'detailUrl' =&gt;Url::to(['expenses/viewdetail']),
     ],

];



echo GridView::widget([
    'dataProvider'=&gt; $dataProvider,
    'filterModel' =&gt; $searchModel,
    'columns' =&gt; $gridColumns,
    'autoXlFormat'=&gt;true,
    'responsive'=&gt;true,
    'hover'=&gt;true,
    'condensed'=&gt;true,
    'floatHeader'=&gt;true,
    'bordered'=&gt;true,
   'toolbar'=&gt;['{export}',
                    '{toggleData}',],
   'showPageSummary'=&gt;true,
   'panel'=&gt;[
       'heading'=&gt;'&lt;h3 class="panel-title"&gt;&lt;i class="glyphicon glyphicon-globe"&gt;&lt;/i&gt; '. Html::encode($this-&gt;title).'&lt;/h3&gt;',
    'type'=&gt;'primary',
    'before'=&gt;Html::a('&lt;i class="glyphicon glyphicon-plus"&gt;&lt;/i&gt;Create Expenses', ['create'], ['class' =&gt; 'btn btn-primary']),
    'showFooter'=&gt;false

    ],
    'pjax'=&gt;true,
    'export'=&gt;[
        'fontAwesome'=&gt;true,
        'showConfirmAlert'=&gt;false,
        'target'=&gt;GridView::TARGET_BLANK,

    ],


]);

?&gt;
</code></pre>