kartik-v / yii2-export

A library to export server/db data in various formats (e.g. excel, html, pdf, csv etc.)
http://demos.krajee.com/export
Other
165 stars 126 forks source link

The export file renders "No results found" but the gridview has data #368

Closed neoacevedo closed 8 months ago

neoacevedo commented 1 year ago

Prerequisites

Steps to reproduce the issue

  1. Setting Export menu widget with the same columns and data provider as in the gridview:
    $fullExport = ExportMenu::widget([
    'dataProvider' => $dataProvider, // The same data provider for the Grid View
    'columns' => $columns, // the same columns for the Grid View
    'target' => ExportMenu::TARGET_SELF,
    'exportContainer' => [
        'class' => 'btn-group mr-2 me-2'
    ],
    'template' => '{menu}',
    'exportConfig' => [
        ExportMenu::FORMAT_HTML => null,
        ExportMenu::FORMAT_EXCEL => null,
        ExportMenu::FORMAT_CSV => null,
        ExportMenu::FORMAT_TEXT => null,
        ExportMenu::FORMAT_EXCEL_X => [
            'alertMsg' => Yii::t('kvexport', 'The EXCEL export file will be generated for download.'),
        ],
        ExportMenu::FORMAT_PDF => [
            'alertMsg' => Yii::t('kvexport', 'The PDF export file will be generated for download.'),
        ],
    ],
    'dropdownOptions' => [
        'label' => 'Exportar',
        'class' => 'btn btn-outline-secondary btn-default',
        'itemsBefore' => [
            '<div class="dropdown-header">Exportar todos los datos</div>',
        ],
    ],
    ]);
    ...
    <?= GridView::widget([
                            'dataProvider' => $dataProvider,
                            'filterModel' => $searchModel,
                            'containerOptions' => ['class' => 'card border-primary'],
                            'bordered' => true,
                            'striped' => true,
                            'condensed' => true,
                            'resizableColumns' => true,
                            'responsive' => true,
                            'responsiveWrap' => false,
                            'hover' => true,
                            'headerRowOptions' => ['class' => 'kv-table-header', 'color' => 'white'],
                            'tableOptions' => ['id' => 'table-cuentas'],
                            'autoXlFormat'=>true,
                            'toolbar' => [
                                // '{export}',
                                $fullExport
                            ],
                            'panel' => [
                                'type'=>'default',
                            ],
                            'columns' => $columnas
                        ]) ?>
  2. Click on any export file option
  3. To generate the file

Expected behavior and actual behavior

The generated file only has the empty text message: "No results found".

The generated file should have at least the same data in the current grid view page.

Environment

Browsers

Operating System

Libraries

Isolating the problem

neoacevedo commented 1 year ago

In addition to this issue, if I set the emptyText to the export menu as 'emptyText' => $dataProvider->count,, the rendered file will display the total count for the dataProvider, and of course, it is >=1. UPDATE: if in the template I set only 'template' => '{menu}', the widget will never send the columns to render, so I must to let the template as the default column-menu because if I let only the menu in the template, the data won't be rendered. So, if I don't want the column selector and I want to get all the data in the files, how should I to do it?

humangrass commented 1 year ago

I faced the same issue. This is due to the logic of GridView and ExportMenu - it is different. Changing the query in the dataProvider allowed me to go further.

kartik-v commented 8 months ago

Check the dataProvider you pass to the GridView and ExportMenu - both are separate settings - and you control the query as part of your Search Model and the controller actions in your app. You need to setup the dataProvider query as per your use case - if you want to mirror the GridView and ExportMenu - ensure you pass the exact same modified dataProvider to both.