kartik-v / yii2-editable

An enhanced editable widget for Yii 2.0 that allows easy editing of displayed data with html inputs, widgets and more.
http://demos.krajee.com/editable
Other
112 stars 55 forks source link

After edit display id, not value #202

Closed zvbyy closed 4 years ago

zvbyy commented 4 years ago

Hello

Did not find a similar problem. I added a new editable column with dropdown to my grid, and after changing the value, the id of the selected value is displayed, not the value itself.

image image image

view:

[
    'headerOptions' => ['style' => 'width:250px'],
    'attribute'=>'prikazWithDate',
    'label'=>'По приказу',
    'class'=>'kartik\grid\EditableColumn',
    'editableOptions'=> function ($model, $key, $index) use($prikazDropDownList) {
        return [
            'size'=>'md',
            'asPopover' => false,
            'formOptions'=>[
                'action'=>yii\helpers\Url::to(['amount-edit', 'id' => Yii::$app->getRequest()->getQueryParam('id')]),
            ],
            'inputType' => Editable::INPUT_DROPDOWN_LIST,
            'options'=>[
                'value'=>$model->prikaz_id,
            ],
            'data'=>$prikazDropDownList,
        ];
    },
],

$prikazDropDownList=[id=>value..]

prikazWithDate in model:

public function getPrikaz()
{
    return $this->hasOne(PrikazList::className(), ['id' => 'prikaz_id']);
}
/**
 * @return string|null
 */
public function getPrikazWithDate(){
    return $this->prikaz?$this->prikaz->prikazWithDate:null;
}

controller:

public function actionAmountEdit($id){
    $currentAmount=new AmountsManipulate();
    $currentAmount->id=$id;
    $currentAmount->amountEditWeb();

    $amounts=Amounts::find()
        ->where(['debt_id'=>$id]);
    $amountModel=new Amounts();

    $prikazDropDownListRequest=PrikazList::find()
        ->where(['main_debt_id'=>$id])
        ->orderBy('period_start_date')
        ->andWhere(['is not','prikaz',null])
        ->all();
    $prikazDropDownList=ArrayHelper::map($prikazDropDownListRequest, 'id',
        function($model){
            return $model['prikaz']." от ".$model['prikaz_date'];
        }
    );
    $prikazDropDownList=[null=>'Платеж не по приказу']+$prikazDropDownList;

    $content=$this->render('debt_tab2-tab3',[
        'amounts'=>$amounts,
        'amountModel'=>$amountModel,
        'status'=>CustomHelpers::status($id),
        'prikazDropDownList'=>$prikazDropDownList,
    ]);

    return Json::encode($content);
}

In the dump $content, the table is correct, a new value is substituted. But id is displayed.

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.