renderHeaderCellContent(), $this->headerOptions); } /** * {@inheritdoc} */ protected function renderHeaderCellContent() { if ($this->header !== null || $this->label === null && $this->attribute === null) { return parent::renderHeaderCellContent(); } $label = $this->getHeaderCellLabel(); if ($this->encodeLabel) { $label = Html::encode($label); } if ($this->attribute !== null && $this->enableSorting && ($sort = $this->grid->dataProvider->getSort()) !== false && $sort->hasAttribute($this->attribute)) { return $sort->link($this->attribute, array_merge($this->sortLinkOptions, ['label' => $label])); } return $label; } /** * {@inheritdoc] */ protected function getHeaderCellLabel() { $provider = $this->grid->dataProvider; if ($this->label === null) { if ($provider instanceof ActiveDataProvider && $provider->query instanceof ActiveQueryInterface) { /* @var $modelClass Model */ $modelClass = $provider->query->modelClass; $model = $modelClass::instance(); $label = $model->getAttributeLabel($this->attribute); } elseif ($provider instanceof ArrayDataProvider && $provider->modelClass !== null) { /* @var $modelClass Model */ $modelClass = $provider->modelClass; $model = $modelClass::instance(); $label = $model->getAttributeLabel($this->attribute); } else { $models = $provider->getModels(); if (($model = reset($models)) instanceof Model) { /* @var $model Model */ $label = $model->getAttributeLabel($this->attribute); } else { $label = Inflector::camel2words($this->attribute); } } } else { $label = $this->label; } return $label; } /** * 返回单元格值 * @param mixed $model * @param mixed $key 模型ID * @param int $index 行号 * @return string */ public function getDataCellValue($model, $key, $index) { if ($this->value !== null) { if (is_string($this->value)) { return ArrayHelper::getValue($model, $this->value); } return call_user_func($this->value, $model, $key, $index, $this); } elseif ($this->attribute !== null) { return ArrayHelper::getValue($model, $this->attribute); } return null; } /** * {@inheritdoc} */ protected function renderDataCellContent($model, $key, $index) { if ($this->content === null) { return $this->grid->formatter->format($this->getDataCellValue($model, $key, $index), $this->format); } return parent::renderDataCellContent($model, $key, $index); } }