kartik-v / yii2-grid

Enhanced GridView with various utilities for Yii Framework 2.0
http://demos.krajee.com/grid
Other
556 stars 303 forks source link

Dynamic filename failes due to genOpts js issue #963

Closed Er-Kalpesh closed 4 years ago

Er-Kalpesh commented 4 years ago

Prerequisites

So I want dynamic filename when I export grid. Like I need all the filter I have applied before grid export. So I have used code like

$output = Helper::array_to_pipe($_GET,'_', [], false,'_');
$filename = "Export_".$page_title."_".$output."_".date('Y-m-d'); 

and inside the config: 'filename' => \Yii::t('kvgrid', $filename),

so it's working perfectly fine when I don't use ajax or pjax. but issue comes when I use ajax and result of it getting error of "The parameters for yii2-grid export seem to be tampered. Please retry!"

Steps to reproduce the issue

  1. So on ajax request it comes to my code and generates new filename from the query params
  2. Comes to file: \vendor\kartik-v\yii2-grid\src\GridView.php protected function registerAssets() ...
    foreach ($this->exportConfig as $format => $setting) {
                $id = "jQuery('#{$gridId} .export-{$format}')";
                $genOpts = Json::encode(
                    [
                        'filename' => $setting['filename'],
                        'showHeader' => $setting['showHeader'],
                        'showPageSummary' => $setting['showPageSummary'],
                        'showFooter' => $setting['showFooter'],
                    ]
                );
                $genOptsVar = 'kvGridExp_' . hash('crc32', $genOpts);
                $view->registerJs("var {$genOptsVar}={$genOpts};");
                $expOpts = Json::encode(
                    [
                        'dialogLib' => ArrayHelper::getValue($this->krajeeDialogSettings, 'libName', 'krajeeDialog'),
                        'gridOpts' => new JsExpression($gridOptsVar),
                        'genOpts' => new JsExpression($genOptsVar),
                        'alertMsg' => ArrayHelper::getValue($setting, 'alertMsg', false),
                        'config' => ArrayHelper::getValue($setting, 'config', []),
                    ]
                );
                $expOptsVar = 'kvGridExp_' . hash('crc32', $expOpts);
                $view->registerJs("var {$expOptsVar}={$expOpts};");
                $script .= "{$id}.gridexport({$expOptsVar});";
            }
  3. And when I debug it shows correct filename here too but it's not reflecting the browser. still, in firefox console, I can see old "genOpts" values. also in \vendor\kartik-v\yii2-grid\src\assets\js\kv-grid-export.js Its retrieving old "genOpts" values when I use pjax.

Environment

Development

Browsers

Operating System

Libraries

Er-Kalpesh commented 4 years ago

I can demonstrate the whole issue over screen share call if its not clear

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.