2amigos / yii2-grid-view-library

Highly enhanced GridView widget and grid components for Yii2
https://2amigos.us
Other
57 stars 16 forks source link

Improve request for Editable Column #9

Closed Insolita closed 10 years ago

Insolita commented 10 years ago

please add ability to set EditableOptions by Closure

tonydspaniard commented 10 years ago

Do you have time for a pull request?

Insolita commented 10 years ago

unfortunately, i can't soon

tonydspaniard commented 10 years ago

@Insolita Please, provide an example... I try to find out time to do it. I have something in mind but I would like to confirm is exactly what you request.

Insolita commented 10 years ago

exapmle - what i want - in gridview

[
                'attribute' => 'position',
                'value' => function ($data) use ($positions) {
                        return $data->position ? $positions[$data->position] : Yii::t('app','Not set');
                    },
                'filter' => $positions,
                'class' => \dosamigos\grid\EditableColumn::className(),
                'url' => ['/widgetman/widgetman/editable'],
                'type' => 'select',
                'editableOptions' => function ($data) use ($module) {
                        return [
                            'emptytext' =>Yii::t('app','Not set'),
                            /**
                                    it`s return options for choose with object specific, don`t want use ajax query
                            **/
                            'source' => \yii\helpers\Json::encode($module->getWidgetPlaces($data->class))  
                        ];
                    }
],

so in your EditableColumn must be something like this

 protected function renderDataCellContent($model, $key, $index)
    {

        $value = parent::renderDataCellContent($model, $key, $index);
       if(is_callable($this->editableOptions)){
           $opts=call_user_func($this->editableOptions, $model, $key, $index);
           foreach ($opts as $prop => $v) { 
            $this->options['data-' . $prop] = $v;              //Not sure about this
           }
       }elseif(is_array($this->editableOptions){
            foreach ($this->editableOptions as $prop => $v) {
            $this->options['data-' . $prop] = $v;
           }
        } 
        $url = (array)$this->url;
        $this->options['data-url'] = Url::to($url);
        $this->options['data-pk'] = $key;
        $this->options['data-name'] = $this->attribute;
        $this->options['data-type'] = $this->type;

        return Html::a($value, null, $this->options);
    }

Thanks a lot for attention

tonydspaniard commented 10 years ago

@Insolita looks good... checking your PR

tonydspaniard commented 10 years ago

closed by #10