javascript - YII2 Kartik - ExportMenu 仅导出选中项目的数据

标签 javascript php plugins yii2 export

我包含 Kartik yii2 ExportMenu 插件,它对于所有数据导出都工作良好,但现在我只想导出在网格上检查的选定行。

<?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,
               ],
          ]);?>

谁能帮我导出仅检查过的数据。 如果您需要任何其他信息相关代码,请询问。 谢谢。

最佳答案

使用此参数将一列添加到您的列配置中:

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

之后您需要编写自己的代码来过滤数据提供程序以仅返回导出菜单中选定的行。因此,您的 GridView 数据提供程序和导出菜单数据提供程序将变得不同,您需要通过 GridView 的选定行来控制导出菜单数据提供程序。

要在 JS 中获取 GriView 的选定行,您可以这样做:

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

欲了解更多信息,请访问:Data widgets Yii2

关于javascript - YII2 Kartik - ExportMenu 仅导出选中项目的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47647214/

相关文章:

plugins - 插件 jar 中的 Gradle 扩展对象(groovy 代码)

javascript - 如何更改 CKEditor 中已注册的对话框

javascript - jQuery 如何通过单击另一个元素来更改元素的类

php - 通过ajax(html)将Html文本发送到php脚本以存储在数据库中。它只保存到

php - 命令在 putty 中工作正常但在 PHP 中不使用 exec()

php - 插入 MySQL 和 PHP

python - Sublime Text 2 插件不会出现在 Command Platte 中

javascript - 如何生成完全不包含任何空格甚至在字符串开头或结尾处不包含空格的正则表达式

javascript - 在 Firefox 中与 Web 内容(页面对象)共享插件对象(内容脚本)

javascript - 在 JS 中换行