Commit c5d65e09 by Carsten Brandt

Refactor DataColum to use model label for sorting link

parent f9fab5d4
...@@ -62,23 +62,31 @@ class DataColumn extends Column ...@@ -62,23 +62,31 @@ class DataColumn extends Column
if ($this->attribute !== null && $this->header === null) { if ($this->attribute !== null && $this->header === null) {
$provider = $this->grid->dataProvider; $provider = $this->grid->dataProvider;
if ($this->enableSorting && ($sort = $provider->getSort()) !== false && $sort->hasAttribute($this->attribute)) { if ($this->enableSorting && ($sort = $provider->getSort()) !== false && $sort->hasAttribute($this->attribute)) {
if (!isset($sort->attributes[$this->attribute]['label'])) {
$sort->attributes[$this->attribute]['label'] = $this->getHeaderLabel();
}
return $sort->link($this->attribute); return $sort->link($this->attribute);
} }
$models = $provider->getModels(); return $this->getHeaderLabel();
if (($model = reset($models)) instanceof Model) { } else {
/** @var Model $model */ return parent::renderHeaderCellContent();
return $model->getAttributeLabel($this->attribute); }
} elseif ($provider instanceof ActiveDataProvider) { }
if ($provider->query instanceof ActiveQuery) {
protected function getHeaderLabel()
{
$provider = $this->grid->dataProvider;
if ($provider instanceof ActiveDataProvider && $provider->query instanceof ActiveQuery) {
/** @var Model $model */ /** @var Model $model */
$model = new $provider->query->modelClass; $model = new $provider->query->modelClass;
return $model->getAttributeLabel($this->attribute); return $model->getAttributeLabel($this->attribute);
} }
$models = $provider->getModels();
if (($model = reset($models)) instanceof Model) {
/** @var Model $model */
return $model->getAttributeLabel($this->attribute);
} }
return Inflector::camel2words($this->attribute); return Inflector::camel2words($this->attribute);
} else {
return parent::renderHeaderCellContent();
}
} }
protected function renderFilterCellContent() protected function renderFilterCellContent()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment