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

not reloading data after pjax #346

Closed kzpromo closed 3 years ago

kzpromo commented 3 years ago

hi, yii2-export not reloading data after pjax sumbit it downloads first loaded data from sqldataprovider

$dataProvider used from SqlDataProvider with sql query

my view

<?php
use kartik\export\ExportMenu;
?>

<hr/>
<?php yii\widgets\Pjax::begin(['id' => 'widget_report_'.$widget->id, 'enablePushState' => true]) ?>
<?=$sql;?>
<div class="row">
    <div class="col-12">
        <?php if(!empty($widget->time_created)):?>
            <?=$this->render('time_filter', ['model' => $filter_date]);?>
        <?php endif;?>
    </div>
</div>

<div class="row">
    <div class="col-12">
        <label>Скачать отчет: </label>
            <?php
                echo ExportMenu::widget([
                    'dataProvider' => $dataProvider,
                    'columns' => $columns,
                    'clearBuffers' => true,
                ]);
            ?>
    </div>
</div>
<hr/>

<?php if($result):?>
<?php
$data_points = array();
$json_data = '';
foreach($result as $vals){
    $p = [
        'label' => $vals[$widget->index_key],
        'y' => $vals[$widget->value]
    ];
    array_push($data_points, $p); 
}
$json_data = json_encode($data_points, JSON_NUMERIC_CHECK);
$width = "100%";
if(!empty($widget->width)){
    $width = $widget->width."px";
}
$height = "500px";
if(!empty($widget->height)){
    $height = $widget->height."px";
}
?>
<div id="report_<?=$widget->id;?>" style="height: <?=$height;?>; width: <?=$width?>;"></div>

<?php
$this->registerJsFile(Yii::$app->request->baseUrl.'/plugins/canvasjs-3.2.9/jquery.canvasjs.min.js',
    ['depends' => [\yii\web\JqueryAsset::className()]
]);
$js = ' 
    var report_'.$widget->id.' = new CanvasJS.Chart("report_'.$widget->id.'", {
        exportEnabled: true,
        animationEnabled: true,
        zoomEnabled: true,
        theme: "light2",
        title:{
            text: "'.$widget->name.'",
            fontSize: 14,
        },
        subtitles: [{
                text: "'.$widget->description.'"
        }],
        axisX: {
            title: "'.$widget->x_label.'",
            labelFontSize: 10,
            titleFontSize: 14,
            labelAngle: 90,
            margin: 20,
        },
        axisY: {
            title: "'.$widget->y_label.'",
            labelFontSize: 10,
            titleFontSize: 14,
            margin: 20,
        },
        data: [{
            type: "line",
            dataPoints: '.$json_data.'
        }]
    });
    report_'.$widget->id.'.render();
';
$this->registerJs($js);
?>
<?php else:?> 
<div class="alert alert-warning">По данному запросу нет результатов</div>
<?php endif;?>
<?php yii\widgets\Pjax::end() ?>

my filter

<?php
use app\widgets\models\FilterDate;
use yii\widgets\ActiveForm;
use yii\helpers\Html;
$filters = FilterDate::time_filters();
?>

<label>Фильтр даты: </label>

<div class="btn-group btn-group-sm" role="group" aria-label="Filters">
<?php foreach($filters as $filter_id => $val):?>
    <?php $form = ActiveForm::begin(['method' => 'post', 'options' => ['data-pjax' => true]]); ?>
        <?= $form->field($model, 'time_filter')->hiddenInput(['value' => $filter_id])->label(false); ?>
        <?php 
        $status = "default";
        if($model->time_filter==$filter_id){
            $status = "success";
        }
        ?>
        <?= Html::submitButton($val, ['class' => 'btn btn-xs btn-'.$status]) ?>
    <?php ActiveForm::end(); ?>
<?php endforeach; ?>
</div>
--- Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/97020501-not-reloading-data-after-pjax?utm_campaign=plugin&utm_content=tracker%2F7668315&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F7668315&utm_medium=issues&utm_source=github).
stale[bot] commented 3 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.