如何访问 Yii2 网格视图数据

how to access Yii2 grid view data

我在我的应用程序中实现了 yii2 网格视图,当我按下打印按钮将其打印为报告时,我需要将网格视图的选定输出传递给 pdf 打印机。 我不知道如何访问网格视图的结果集并将其传递给我的控制器操作

我正在使用 kartik mpdf 扩展生成 pdf

https://imgur.com/a/cGGt968

当我按下打印按钮时,我需要在网格视图中获取数据并将其传递到 mpdf 扩展中。

这是我的视图文件的一部分

<h5>Details of Education Qualification</h5>
<?php
echo Html::a('<i class="fa far fa-hand-point-up"></i> Print', ['/pdfrpt/report'], [
    'class'=>'btn btn-danger', 
    'target'=>'_blank', 
    'data-toggle'=>'tooltip', 
    'title'=>'Will open the generated PDF file in a new window'
]);
?>

<?php Pjax::begin(); ?>
    <?php // echo $this->render('_search', ['model' => $searchModel]); ?>
    <?= GridView::widget([
        'dataProvider' => $dataProvider,
        'filterModel' => $searchModel,
        'columns' => [
            ['class' => 'yii\grid\SerialColumn'],

        'EmpNo',
        ['attribute'=> 'nameWithInitial',
          'label' => 'Name',
            'value' =>'empNo.nameWithInitial',],

这就是我调用 pdf 的方式(在 pdfrpt 控制器中报告操作)

     public function actionReport() {
        Yii::$app->response->format = \yii\web\Response::FORMAT_RAW;
        $pdf = new Pdf([
            'mode' => Pdf::MODE_CORE, 
            'destination' => Pdf::DEST_BROWSER,
            'content' => $this->renderPartial('test'),// here  I need to specify current grid view data
            'options' => [

            ],
            'methods' => [
                'SetTitle' => 'Report title',
                'SetSubject' => 'Generating PDF files via yii2-mpdf extension has never been easy',
                'SetHeader' => ['report title||Generated On: ' . date("r")],
                'SetFooter' => ['|Page {PAGENO}|'],
                'SetAuthor' => '',
                'SetCreator' => '',
                'SetKeywords' => ' ',
            ]
        ]);
        return $pdf->render();
    }

您使用了 pagination false,否则它将为第一页提供数据。

  // create the data provider by configuring its pagination and sort properties
    $provider = new XyzDataProvider([
        'pagination' => [...],
        'sort' => [...],
    ]);

    // retrieves paginated and sorted data
    $models = $provider->getModels();

    // get the number of data items in the current page
    $count = $provider->getCount();

    // get the total number of data items across all pages
    $totalCount = $provider->getTotalCount();