dounai9592 2017-12-05 06:17 采纳率: 100%
浏览 207
已采纳

YII2 Kartik - ExportMenu仅使用选中项目导出数据

I include Kartik yii2 ExportMenu plugin and its working fine for all data export but now I want to export only selected rows which is checked on grid.

<?php 
  $gridColumns = [
      ['class' => 'yii\grid\SerialColumn'],
      'username',
      'email',
      [
         'label' => Yii::t('app','User Access'),
         'value' => function($model){ 
              if($model->access_level == 1) { return 'Read/Write/Import/Export'; }
              if($model->access_level == 2) { return 'Read/Write'; }
              if($model->access_level == 3) { return 'Read'; }
            }
      ],
      'fullname',
      // [
      //    'label' => Yii::t('app','Status'),
      //    'value' => function($model){ 
      //         if($model->status == 10) { return 'Active'; }
      //         if($model->status == 0) { return 'Inactive'; }
      //       }
      // ],
      [
     'attribute' => 'created_at',
     'format' => ['date' , 'php:d/m/Y'],
     'label' => Yii::t('app','Created On'),
     'headerOptions' => ['style' => 'width:12%;'],
      ],
      [
         'attribute' => 'updated_at',
         'format' => ['date' , 'php:d/m/Y'],
         'label' => Yii::t('app','Modified On'),
         'headerOptions' => ['style' => 'width:12%;'],
      ],
      // 'updated_by',
      [
         'attribute' => 'updated_by',
         'label' => Yii::t('app','Modified By'),
         'headerOptions' => ['style' => 'width:12%;'],
        'value' => 'user.username',
        //  'value' => function($model){ 
        //       return $model->user->username;
        // }
      ],

      // ['class' => 'yii\grid\ActionColumn'],
  ]; 
      echo ExportMenu::widget([
               'dataProvider' => $dataProvider,
               'columns' => $gridColumns,
               'target' => ExportMenu::TARGET_BLANK,
               'showConfirmAlert' => false,
               'filename' => 'Users',
               'dropdownOptions' => [
                'label' => 'Export',
                'class' => 'btn btn-info', 
                'export' => true,
                'toolbar'=>[
                '{export}',
                '{toggleData}'
                ]          
              ],
               'exportConfig'=>[
               ExportMenu::FORMAT_HTML=>false,
               ExportMenu::FORMAT_TEXT=>false,
               ExportMenu::FORMAT_PDF=>false,
               ExportMenu::FORMAT_EXCEL=>false,
               ],
          ]);?>

Can anyone please help me to export data which is checked only . If you need any other information related code please ask. Thanks.

  • 写回答

1条回答 默认 最新

  • dqxyh48864 2017-12-05 12:09
    关注

    Add a column to your columns onfiguration with this param:

    [
        'class' => 'kartik\grid\CheckboxColumn',
        'headerOptions' => ['class' => 'kartik-sheet-style'],
    ],
    

    And after you need to write your own code that will filter the data provider to return only selected rows in export menu. So your grid view data provider and export menu data provider will become different and you need to control the export menu data provider via the selected rows of grid view.

    For get selected rows of GriView in JS you can to this:

    var keys = $('#grid').yiiGridView('getSelectedRows');
    // keys is an array consisting of the keys associated with the selected rows
    

    For more info visit: Data widgets Yii2

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类