在Yii2 Gridview中发出自定义可编辑下拉列表

时间:2017-07-27 01:31:27

标签: php gridview yii2 dropdown editablegrid

我试图在Gridview中设置Kartik Editable。我尝试使用可编辑:: INPUT_DROPDOWN_LIST ,其选项取决于来自其他列的数据

这是视图enter image description here

我在ID Ket.列中设置了可编辑状态,下拉列表的选项取决于列Kode Jenis的值。

这是我网格中的代码

            ['class' => 'kartik\grid\EditableColumn',
            'attribute' => 'id_keterangan_tambahan',
            'vAlign' => 'middle',
            'headerOptions' => ['class' => 'kv-sticky-column'],
            'contentOptions' => ['class' => 'kv-sticky-column'],
            'editableOptions' => [
                'data' =>
                [
                    function ($model, $key, $index, $widget) {
                        $kode_jenis = $model->kode_jenis;
                        switch ($kode_jenis) {
                            case "07":
                                $t = [
                                    1 => '1',
                                    2 => '2',
                                    3 => '3',
                                    4 => '4',
                                    5 => '5',
                                    6 => '6'
                                ];
                                break;
                            case "08":
                                $t = [
                                    1 => '1',
                                    2 => '2',
                                    3 => '3',
                                    4 => '4',
                                ];
                                break;
                            default:
                                $t = [
                                    0 => '0',
                                ];
                                break;
                        }
                        return $t;
                    },
                ],
                'options' => ['class' => 'form-control', 'prompt' => 'Select ID...'],
                'displayValueConfig' => [
                    '0' => '0 <i class="glyphicon glyphicon-ok" style="color: green"></i>',
                    '9' => '- <i class="glyphicon glyphicon-remove" style="color: #ff0000"></i>',
                ],
                'header' => 'ID Keterangan Tambahan',
                'size' => 'md',
                'inputType' => Editable::INPUT_DROPDOWN_LIST,
                'widgetClass' => 'kartik\datecontrol\DateControl',
                'options' => [
                    'type' => Editable::INPUT_DROPDOWN_LIST,
                    'options' => [
                        'pluginOptions' => [
                            'autoclose' => true
                        ]
                    ]
                ]
            ],
        ],
        [
            'attribute' => 'kode_jenis',
            'value' => function($data) {
                return $data->kode_jenis;
            },
            'hAlign' => 'center',
            'width' => '175px',
        ],

下拉列表仅显示Kode Jenis 07 or 08的选项。

但是我得到了这样的错误

  

htmlspecialchars()期望参数1为字符串,给定对象

我的代码是对的吗?如果不是,我该怎么做?

0 个答案:

没有答案