Moeez
Moeez

Reputation: 478

How to change file name in kartik export yii2

Hi I am using kartik export in my yii2 project.

 <?=
        ExportMenu::widget([
            'dataProvider' => $dataProvider,
            'columns' => $gridColumns,
            'dropdownOptions' => [
                'label' => 'Export All',
                'class' => 'btn btn-info',

            ],
            'exportConfig' => [
                             ExportMenu::FORMAT_PDF => false,
                             ExportMenu::FORMAT_TEXT => false,
                             ExportMenu::FORMAT_HTML => false,
                             ExportMenu::FORMAT_CSV => false,
                             ExportMenu::FORMAT_EXCEL => ['filename' => 'Installation_data'.date('dd-MM-yy')],
                             ExportMenu::FORMAT_EXCEL => ['filename' => 'Installation_data'.date('dd-MM-yy')],
                         ],

        ])?>

        <br><br>

        <?= GridView::widget([
            'dataProvider' => $dataProvider,
            'filterModel' => $searchModel,
            'columns' => $gridColumns,

        ]); ?>

Now I want to change the file name. I have added the file name option but it's not working.

How can I change the name ?

Any help would be highly appreciated.

Upvotes: 1

Views: 1399

Answers (1)

ttrasn
ttrasn

Reputation: 4851

From document you can change filename with ExportMenu option attribute filename

try this:

ExportMenu::widget([
        'dataProvider' => $dataProvider,
        'columns' => $gridColumns,
        'dropdownOptions' => [
            'label' => 'Export All',
            'class' => 'btn btn-info',

        ],
        'exportConfig' => [
                         ExportMenu::FORMAT_PDF => false,
                         ExportMenu::FORMAT_TEXT => false,
                         ExportMenu::FORMAT_HTML => false,
                         ExportMenu::FORMAT_CSV => false,
                         ExportMenu::FORMAT_EXCEL => ['filename' => 'Installation_data'.date('dd-MM-yy')],
                     ],
        'filename' => 'Installation_data'.date('dd-MM-yy')

    ])?>

Upvotes: 3

Related Questions