From 381216595d9cd8caf6d6ff8979ceae8ec86a1758 Mon Sep 17 00:00:00 2001 From: Carsten Brandt Date: Sun, 25 Aug 2013 00:37:29 +0200 Subject: [PATCH] DataColumn: Allow setting label of sort link via short syntax attribute:type:Header should also affect sort link --- framework/yii/grid/DataColumn.php | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/framework/yii/grid/DataColumn.php b/framework/yii/grid/DataColumn.php index ed6e803..e1913c3 100644 --- a/framework/yii/grid/DataColumn.php +++ b/framework/yii/grid/DataColumn.php @@ -59,14 +59,16 @@ class DataColumn extends Column protected function renderHeaderCellContent() { - if ($this->attribute !== null && $this->header === null) { - $provider = $this->grid->dataProvider; - 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); + $provider = $this->grid->dataProvider; + if ($this->attribute !== null && $this->enableSorting && + ($sort = $provider->getSort()) !== false && $sort->hasAttribute($this->attribute)) { + + $label = $this->getHeaderLabel(); + if (($this->header !== null || !isset($sort->attributes[$this->attribute]['label'])) && trim($label) !== '') { + $sort->attributes[$this->attribute]['label'] = $label; } + return $sort->link($this->attribute); + } elseif ($this->header === null) { return $this->getHeaderLabel(); } else { return parent::renderHeaderCellContent(); @@ -76,6 +78,9 @@ class DataColumn extends Column protected function getHeaderLabel() { $provider = $this->grid->dataProvider; + if ($this->header !== null) { + return $this->header; + } if ($provider instanceof ActiveDataProvider && $provider->query instanceof ActiveQuery) { /** @var Model $model */ $model = new $provider->query->modelClass;