/** * Renders the data cell content. * @param mixed $model the data model * @param mixed $key the key associated with the data model * @param integer $index the zero-based index of the data model among the models array returned by [[GridView::dataProvider]]. * * @return string the rendering result * @throws InvalidConfigException */ public function renderDataCellContent($model, $key, $index) { $exception = false; $this->_editableOptions = $this->editableOptions; if (!empty($this->editableOptions) && $this->editableOptions instanceof Closure) { $this->_editableOptions = call_user_func($this->editableOptions, $model, $key, $index); } if (!is_array($this->_editableOptions)) { $this->_editableOptions = []; } if ($this->grid->pjax && empty($this->_editableOptions['pjaxContainerId'])) { $this->_editableOptions['pjaxContainerId'] = $this->grid->pjaxSettings['options']['id']; } if ($this->attribute !== null) { $this->_editableOptions['model'] = $model; $this->_editableOptions['attribute'] = '[' . $index . ']' . $this->attribute; } elseif (empty($this->_editableOptions['name']) && empty($this->_editableOptions['model'])) { $exception = true; } elseif (empty($this->_editableOptions['attribute'])) { $exception = true; } if ($exception) { throw new InvalidConfigException("You must setup either the 'attribute' for the EditableColumn OR setup the 'name' OR 'model'/'attribute' in '_editableOptions' (Exception raised for: key: '{$key}', index: '{$index}')."); } $this->_editableOptions['displayValue'] = parent::renderDataCellContent($model, $key, $index); $params = Html::hiddenInput('editableIndex', $index) . Html::hiddenInput('editableKey', $key); if (empty($this->_editableOptions['beforeInput'])) { $this->_editableOptions['beforeInput'] = $params; } else { $this->_editableOptions['beforeInput'] .= $params; } if ($this->refreshGrid) { $view = $this->grid->getView(); $grid = 'jQuery("#' . $this->grid->options['id'] . '")'; $script = <<<JS {$grid}.find('.kv-editable-input').each(function() { var \$input = \$(this); \$input.on('editableSuccess', function(){ {$grid}.yiiGridView("applyFilter"); }); }); JS; $view->registerJs($script); } return Editable::widget($this->_editableOptions); }
/** * Renders the data cell content. * * @param mixed $model the data model * @param mixed $key the key associated with the data model * @param integer $index the zero-based index of the data model among the models array returned by * [[GridView::dataProvider]]. * * @return string the rendering result * @throws InvalidConfigException */ public function renderDataCellContent($model, $key, $index) { $readonly = $this->readonly; if ($readonly instanceof Closure) { $readonly = call_user_func($readonly, $model, $key, $index, $this); } if ($readonly === true) { return parent::renderDataCellContent($model, $key, $index); } $this->_editableOptions = $this->editableOptions; if (!empty($this->editableOptions) && $this->editableOptions instanceof Closure) { $this->_editableOptions = call_user_func($this->editableOptions, $model, $key, $index, $this); } if (!is_array($this->_editableOptions)) { $this->_editableOptions = []; } $options = ArrayHelper::getValue($this->_editableOptions, 'containerOptions', []); Html::addCssClass($options, $this->_css); $this->_editableOptions['containerOptions'] = $options; if ($this->grid->pjax && empty($this->_editableOptions['pjaxContainerId'])) { $this->_editableOptions['pjaxContainerId'] = $this->grid->pjaxSettings['options']['id']; } $strKey = $key; if (empty($key)) { throw new InvalidConfigException("Invalid or no primary key found for the grid data."); } elseif (!is_string($key) && !is_numeric($key)) { $strKey = serialize($key); } if ($this->attribute !== null) { $this->_editableOptions['model'] = $model; $this->_editableOptions['attribute'] = "[{$index}]{$this->attribute}"; $type = ArrayHelper::getValue($this->_editableOptions, 'inputType', Editable::INPUT_TEXT); } elseif (empty($this->_editableOptions['name']) && empty($this->_editableOptions['model']) || !empty($this->_editableOptions['model']) && empty($this->_editableOptions['attribute'])) { throw new InvalidConfigException("You must setup the 'attribute' for your EditableColumn OR set one of 'name' OR 'model' & 'attribute' in 'editableOptions' (Exception at index: '{$index}', key: '{$strKey}')."); } $val = $this->getDataCellValue($model, $key, $index); if (!isset($this->_editableOptions['displayValue']) && $val !== null && $val !== '') { $this->_editableOptions['displayValue'] = parent::renderDataCellContent($model, $key, $index); } $params = Html::hiddenInput('editableIndex', $index) . Html::hiddenInput('editableKey', $strKey); if (empty($this->_editableOptions['beforeInput'])) { $this->_editableOptions['beforeInput'] = $params; } else { $output = $this->_editableOptions['beforeInput']; $this->_editableOptions['beforeInput'] = function ($form, $widget) use($output, $params) { if ($output instanceof Closure) { return $params . call_user_func($output, $form, $widget); } else { return $params . $output; } }; } if ($this->refreshGrid) { $view = $this->grid->getView(); $grid = 'jQuery("#' . $this->grid->options['id'] . '")'; $script = <<<JS {$grid}.find('.{$this->_css}').each(function() { var \$el = \$(this); \$el.on('editableSuccess', function(){ {$grid}.yiiGridView("applyFilter"); }); }); JS; $view->registerJs($script); } return Editable::widget($this->_editableOptions); }
/** * Renders the data cell content. * * @param mixed $model the data model * @param mixed $key the key associated with the data model * @param integer $index the zero-based index of the data model among the models array returned by * [[GridView::dataProvider]]. * * @return string the rendering result * @throws InvalidConfigException */ public function renderDataCellContent($model, $key, $index) { $readonly = $this->readonly; if ($readonly instanceof Closure) { $readonly = call_user_func($readonly, $model, $key, $index, $this); } if ($readonly === true) { return parent::renderDataCellContent($model, $key, $index); } $this->_editableOptions = $this->editableOptions; if (!empty($this->editableOptions) && $this->editableOptions instanceof Closure) { $this->_editableOptions = call_user_func($this->editableOptions, $model, $key, $index, $this); } if (!is_array($this->_editableOptions)) { $this->_editableOptions = []; } $options = ArrayHelper::getValue($this->_editableOptions, 'containerOptions', []); Html::addCssClass($options, $this->_css); $this->_editableOptions['containerOptions'] = $options; if ($this->grid->pjax && empty($this->_editableOptions['pjaxContainerId'])) { $this->_editableOptions['pjaxContainerId'] = $this->grid->pjaxSettings['options']['id']; } $strKey = $key; if (empty($key)) { throw new InvalidConfigException("Invalid or no primary key found for the grid data."); } elseif (!is_string($key) && !is_numeric($key)) { $strKey = serialize($key); } if ($this->attribute !== null) { $this->_editableOptions['model'] = $model; $this->_editableOptions['attribute'] = "[{$index}]{$this->attribute}"; } elseif (empty($this->_editableOptions['name']) && empty($this->_editableOptions['model']) || !empty($this->_editableOptions['model']) && empty($this->_editableOptions['attribute'])) { throw new InvalidConfigException("You must setup the 'attribute' for your EditableColumn OR set one of 'name' OR 'model' & 'attribute'" . " in 'editableOptions' (Exception at index: '{$index}', key: '{$strKey}')."); } $val = $this->getDataCellValue($model, $key, $index); if (!isset($this->_editableOptions['displayValue']) && $val !== null && $val !== '') { $this->_editableOptions['displayValue'] = parent::renderDataCellContent($model, $key, $index); } $params = Html::hiddenInput('editableIndex', $index) . Html::hiddenInput('editableKey', $strKey) . Html::hiddenInput('editableAttribute', $this->attribute); if (empty($this->_editableOptions['beforeInput'])) { $this->_editableOptions['beforeInput'] = $params; } else { $output = $this->_editableOptions['beforeInput']; $this->_editableOptions['beforeInput'] = function ($form, $widget) use($output, $params) { if ($output instanceof Closure) { return $params . call_user_func($output, $form, $widget); } else { return $params . $output; } }; } if ($this->refreshGrid) { $id = $this->grid->options['id']; $this->_view->registerJs("kvRefreshEC('{$id}','{$this->_css}');"); } return Editable::widget($this->_editableOptions); }