Saturday, June 11, 2016

Error: This page can't be reached in Kartik Yii2 Export

Leave a Comment

In Kartik Yii2 Export, While exporting as Excel am getting This Page Cant't Reached Error in Localhost.

if i export as Text or CSV, export get worked but if i open the exported file Text or CSV, Half the report is printing like html code

Help will be really appreciated.

GridCode:

 <?php $gridColumns = [             ['class' => 'yii\grid\SerialColumn'],                 'membercode',                 'member_name',                 [                    'attribute' => 'payment_category',                    'format' => 'raw',                    'label' => 'Payment Category',                    'value' => function($model, $key, $index, $grid) {                         $temp = $model->payment_category;                         $si = Category::find()->where(['category_id' => $temp])->one();                         return $si['category_name'];                     },                   ],                 'member_gender',                 'member_address:ntext',                 'payment_date',                 'amount',                 'receipt_no',                 'payment_mode',                 'pledge_amount',                 'young_amount',                 'tv_amount',                 'building_amount',                 [                    'attribute' => 'payment_subcategory',                    'format' => 'raw',                    'value' => function($model, $key, $index, $grid) {                         $exp = explode(',', $model->payment_subcategory);                         $relation_name = ArrayHelper::map(Subcategory::find()->where(['subcategory_id' => $exp])->all(), 'subcategory_id', 'subcategory_name');                         $relation = implode(',', $relation_name);                         return $relation;                     },                     'filter' => Html::activeDropDownList($searchModel, 'payment_subcategory', ArrayHelper::map(Subcategory::find()->asArray()->all(), 'id', 'subcategory_name'),['class'=>'form-control','multiple' => true]),                 ],             ['class' => 'yii\grid\ActionColumn'],         ]; ?>      <?= ExportMenu::widget([             'dataProvider' => $dataProvider,             'columns' => $gridColumns,             'columnSelectorOptions'=>[                 'label' => 'Columns',                 'class' => 'btn btn-danger'             ],             'fontAwesome' => true,             'dropdownOptions' => [                 'label' => 'Export All',                 'class' => 'btn btn-primary'             ]         ]); ?>      <?= GridView::widget([         'dataProvider' => $dataProvider,         'filterModel' => $searchModel,         'columns' => $gridColumns,         'pager' => [             'firstPageLabel' => 'First',             'lastPageLabel' => 'Last',         ],     ]); ?> 

Above is my Grid view Code. Help will be really appreciated.

Updated:

Error geeting while exporting as CSV:

Error CSV

Error geeting while exporting as EXCEL

error on EXCEL

3 Answers

Answers 1

There is an issue in your gridview, one of the field in gridview carries "=" equal to sign. please check it out PhpOffice/PhpExcel

Answers 2

Try exportConfig settings this

 <?= ExportMenu::widget([         'dataProvider' => $dataProvider,         'columns' => $gridColumns,         'columnSelectorOptions'=>[             'label' => 'Columns',             'class' => 'btn btn-danger'         ],         'fontAwesome' => true,         'dropdownOptions' => [             'label' => 'Export All',             'class' => 'btn btn-primary'         ]         'exportConfig' => [     ExportMenu::FORMAT_HTML => false,     ExportMenu::FORMAT_TEXT => false, ],     ]); ?> 

Answers 3

Try this code for your GridVew::Widget:

  GridView::widget([     'dataProvider' => $dataProvider,     'filterModel' => $searchModel,     'columns' => $gridColumns,     'exportConfig'=> [         GridView::CSV=>[             'label' => 'CSV',             'icon' => '',             'iconOptions' => '',             'showHeader' => false,             'showPageSummary' => false,             'showFooter' => false,             'showCaption' => false,             'filename' => 'yii',             'alertMsg' => 'created',             'options' => ['title' => 'Semicolon -  Separated Values'],             'mime' => 'application/csv',             'config' => [                 'colDelimiter' => ";",                 'rowDelimiter' => "\r\n",             ],          ],     ], ]); 
If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment