2017-12-05 9 views
0

私はKartik yii2 ExportMenuプラグインとすべてのデータのエクスポートに有効ですが、グリッドでチェックされている選択された行のみをエクスポートします。YII2 Kartik - 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'], 
], 

し、エクスポートメニューでのみ選択された行を返すために、データプロバイダをフィルタします独自のコードを記述する必要があります後:

答えて

1

あなたの列に列を追加しますが、このPARAMでonfiguration。グリッドビューのデータプロバイダとエクスポートメニューのデータプロバイダが異なるため、選択したグリッドビューの行を使用してエクスポートメニューのデータプロバイダを制御する必要があります。 Data widgets Yii2

:より多くの情報訪問のため

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

:あなたはこれにJSでGriViewの行をすることができ、選択し得るために

関連する問題