2017-05-30 55 views
0

自定義的CheckBoxList我有這樣的數組基於查詢:Yii2 - 在Yii2

$modelPipe = Pipe::find() 
     ->select([ 
      "size", 
      "container", 
      "seal", 
      "concat(container_seal, '<br>' , size) as container_seal", 
      "count(size) as bundles", 
      "sum(piece) as pieces", 
      "bundle_group" 
     ]) 

     ->where(['outgoing_pipe_id' => NULL]) 
     ->groupBy(['bundle_group']) 
     ->orderBy(['bundle_group' => SORT_ASC]) 
     ->all(); 

這樣

+-----------------------+--------------------------------------------------+---------+--------+--------------+ 
| size     | container_seal         | bundles | pieces | bundle_group | 
+-----------------------+--------------------------------------------------+---------+--------+--------------+ 
| 35 x 35 x 0.85 x 6000 | EITU1268671/ EMCCSQ5920<br>35 x 35 x 0.85 x 6000 |  24 | 2400 |   1 | 
| 15 x 35 x 0.75 x 6000 | EITU1268671/ EMCCSQ5920<br>15 x 35 x 0.75 x 6000 |  20 | 2000 |   2 | 
| 35 x 35 x 0.85 x 6000 | EITU1374987/ EMCCSQ6086<br>35 x 35 x 0.85 x 6000 |  24 | 2400 |   3 | 
| 15 x 35 x 0.75 x 6000 | EITU1374987/ EMCCSQ6086<br>15 x 35 x 0.75 x 6000 |  20 | 2000 |   4 | 
| 35 x 35 x 0.75 x 6000 | EITU1842100/ EMCCSQ6096<br>35 x 35 x 0.75 x 6000 |  18 | 1800 |   5 | 
| 15 x 35 x 0.75 x 6000 | EITU1842100/ EMCCSQ6096<br>15 x 35 x 0.75 x 6000 |  34 | 3400 |   6 | 
| 35 x 35 x 0.75 x 6000 | DRYU9850060/ EMCCSQ6056<br>35 x 35 x 0.75 x 6000 |  18 | 1800 |   7 | 
| 15 x 35 x 0.75 x 6000 | DRYU9850060/ EMCCSQ6056<br>15 x 35 x 0.75 x 6000 |  34 | 3400 |   8 | 
| 35 x 35 x 0.75 x 6000 | DFSU6646389/ EMCCSQ6626<br>35 x 35 x 0.75 x 6000 |  18 | 1800 |   9 | 
| 15 x 35 x 0.75 x 6000 | DFSU6646389/ EMCCSQ6626<br>15 x 35 x 0.75 x 6000 |  34 | 3400 |   10 | 
| 35 x 35 x 0.75 x 6000 | TCLU4970557/ EMCCSQ6006<br>35 x 35 x 0.75 x 6000 |  18 | 1800 |   11 | 
| 15 x 35 x 0.75 x 6000 | TCLU4970557/ EMCCSQ6006<br>15 x 35 x 0.75 x 6000 |  34 | 3400 |   12 | 
| 35 x 35 x 0.75 x 6000 | FCIU9214153/ EMCCSQ6556<br>35 x 35 x 0.75 x 6000 |  24 | 2400 |   13 | 
| 15 x 35 x 0.85 x 6000 | FCIU9214153/ EMCCSQ6556<br>15 x 35 x 0.85 x 6000 |  22 | 2200 |   14 | 
| 35 x 35 x 0.75 x 6000 | DFSU6912998/ EMCCSQ6536<br>35 x 35 x 0.75 x 6000 |  24 | 2400 |   15 | 
| 15 x 35 x 0.85 x 6000 | DFSU6912998/ EMCCSQ6536<br>15 x 35 x 0.85 x 6000 |  22 | 2200 |   16 | 
| 35 x 35 x 0.85 x 6000 | TEMU6099067/ EMCCSQ6566<br>35 x 35 x 0.85 x 6000 |  4 | 400 |   17 | 
| 35 x 35 x 0.75 x 6000 | TEMU6099067/ EMCCSQ6566<br>35 x 35 x 0.75 x 6000 |  20 | 2000 |   18 | 
| 15 x 35 x 0.85 x 6000 | TEMU6099067/ EMCCSQ6566<br>15 x 35 x 0.85 x 6000 |  20 | 2000 |   19 | 
| 35 x 35 x 0.85 x 6000 | EITU1153733/ EMCCSQ6956<br>35 x 35 x 0.85 x 6000 |  6 | 600 |   20 | 
| 15 x 35 x 0.85 x 6000 | EITU1153733/ EMCCSQ6956<br>15 x 35 x 0.85 x 6000 |  17 | 1700 |   21 | 
| 15 x 35 x 0.75 x 6000 | EITU1153733/ EMCCSQ6956<br>15 x 35 x 0.75 x 6000 |  30 | 3000 |   22 | 
| 15 x 35 x 0.85 x 6000 | EITU1153733/ EMCCSQ6956<br>15 x 35 x 0.85 x 6000 |  1 |  8 |   23 | 
| 15 x 35 x 0.75 x 6000 | EITU1153733/ EMCCSQ6956<br>15 x 35 x 0.75 x 6000 |  1 |  26 |   24 | 
+-----------------------+--------------------------------------------------+---------+--------+--------------+ 

問題是查詢的結果,我需要使用的CheckBoxList爲interprated的上面的數據。 所以,我寫的是這樣的:

<?php 
    $data = ArrayHelper::map($modelPipe, "bundle_group", "container_seal");?> 

    <?= $form->field($model, 'nomors_urut_per_bundle') 
     ->label(false) 
     ->checkboxList($data); 
    ?> 

而且我得到這樣的: image

我怎樣才能獲得視圖我的用戶只需像普通表,該表第一列是一個複選框?

請指教。 謝謝。

+-----------------------+--------------------------------------------------+---------+--------+--------------+ 
| check/uncheck all | size     | container_seal         | bundles | pieces | bundle_group | 
+-----------------------+--------------------------------------------------+---------+--------+--------------+ 
| check/uncheck  | 35 x 35 x 0.85 x 6000 | EITU1268671/ EMCCSQ5920<br>35 x 35 x 0.85 x 6000 |  24 | 2400 |   1 | 
| check/uncheck  | 15 x 35 x 0.75 x 6000 | EITU1268671/ EMCCSQ5920<br>15 x 35 x 0.75 x 6000 |  20 | 2000 |   2 | 
| check/uncheck  | 35 x 35 x 0.85 x 6000 | EITU1374987/ EMCCSQ6086<br>35 x 35 x 0.85 x 6000 |  24 | 2400 |   3 | 
| check/uncheck  | 15 x 35 x 0.75 x 6000 | EITU1374987/ EMCCSQ6086<br>15 x 35 x 0.75 x 6000 |  20 | 2000 |   4 | 
| check/uncheck  | 35 x 35 x 0.75 x 6000 | EITU1842100/ EMCCSQ6096<br>35 x 35 x 0.75 x 6000 |  18 | 1800 |   5 | 
| check/uncheck  | 15 x 35 x 0.75 x 6000 | EITU1842100/ EMCCSQ6096<br>15 x 35 x 0.75 x 6000 |  34 | 3400 |   6 | 
| check/uncheck  | 35 x 35 x 0.75 x 6000 | DRYU9850060/ EMCCSQ6056<br>35 x 35 x 0.75 x 6000 |  18 | 1800 |   7 | 
| check/uncheck  | 15 x 35 x 0.75 x 6000 | DRYU9850060/ EMCCSQ6056<br>15 x 35 x 0.75 x 6000 |  34 | 3400 |   8 | 
| check/uncheck  | 35 x 35 x 0.75 x 6000 | DFSU6646389/ EMCCSQ6626<br>35 x 35 x 0.75 x 6000 |  18 | 1800 |   9 | 
| check/uncheck  | 15 x 35 x 0.75 x 6000 | DFSU6646389/ EMCCSQ6626<br>15 x 35 x 0.75 x 6000 |  34 | 3400 |   10 | 
| check/uncheck  | 35 x 35 x 0.75 x 6000 | TCLU4970557/ EMCCSQ6006<br>35 x 35 x 0.75 x 6000 |  18 | 1800 |   11 | 
| check/uncheck  | 15 x 35 x 0.75 x 6000 | TCLU4970557/ EMCCSQ6006<br>15 x 35 x 0.75 x 6000 |  34 | 3400 |   12 | 
| check/uncheck  | 35 x 35 x 0.75 x 6000 | FCIU9214153/ EMCCSQ6556<br>35 x 35 x 0.75 x 6000 |  24 | 2400 |   13 | 
| check/uncheck  | 15 x 35 x 0.85 x 6000 | FCIU9214153/ EMCCSQ6556<br>15 x 35 x 0.85 x 6000 |  22 | 2200 |   14 | 
| check/uncheck  | 35 x 35 x 0.75 x 6000 | DFSU6912998/ EMCCSQ6536<br>35 x 35 x 0.75 x 6000 |  24 | 2400 |   15 | 
| check/uncheck  | 15 x 35 x 0.85 x 6000 | DFSU6912998/ EMCCSQ6536<br>15 x 35 x 0.85 x 6000 |  22 | 2200 |   16 | 
| check/uncheck  | 35 x 35 x 0.85 x 6000 | TEMU6099067/ EMCCSQ6566<br>35 x 35 x 0.85 x 6000 |  4 | 400 |   17 | 
| check/uncheck  | 35 x 35 x 0.75 x 6000 | TEMU6099067/ EMCCSQ6566<br>35 x 35 x 0.75 x 6000 |  20 | 2000 |   18 | 
| check/uncheck  | 15 x 35 x 0.85 x 6000 | TEMU6099067/ EMCCSQ6566<br>15 x 35 x 0.85 x 6000 |  20 | 2000 |   19 | 
| check/uncheck  | 35 x 35 x 0.85 x 6000 | EITU1153733/ EMCCSQ6956<br>35 x 35 x 0.85 x 6000 |  6 | 600 |   20 | 
| check/uncheck  | 15 x 35 x 0.85 x 6000 | EITU1153733/ EMCCSQ6956<br>15 x 35 x 0.85 x 6000 |  17 | 1700 |   21 | 
| check/uncheck  | 15 x 35 x 0.75 x 6000 | EITU1153733/ EMCCSQ6956<br>15 x 35 x 0.75 x 6000 |  30 | 3000 |   22 | 
| check/uncheck  | 15 x 35 x 0.85 x 6000 | EITU1153733/ EMCCSQ6956<br>15 x 35 x 0.85 x 6000 |  1 |  8 |   23 | 
| check/uncheck  | 15 x 35 x 0.75 x 6000 | EITU1153733/ EMCCSQ6956<br>15 x 35 x 0.75 x 6000 |  1 |  26 |   24 | 
+-----------------------+--------------------------------------------------+---------+--------+--------------+ 

回答

0

你可以使用一個GridView正常yii\grid\CheckboxColumn柱只是用['class' => 'yii\grid\CheckboxColumn']http://www.yiiframework.com/doc-2.0/yii-grid-checkboxcolumn.html

最終你可以使用一個回調函數管理正確的選項,例如:

echo GridView::widget([ 
    'id' => 'griditems', 
    'dataProvider' => $dataProvider, 
    'columns' => [ 
     ....... 
     [ 
      'class' => 'yii\grid\CheckboxColumn', 'checkboxOptions' => function($model) { 
        return ['value' => $model->your_value]; 
       }, 
     ], 
    ], 
    ]);