|
|
@ -28,6 +28,14 @@ class DataColumn extends Column |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public $attribute; |
|
|
|
public $attribute; |
|
|
|
/** |
|
|
|
/** |
|
|
|
|
|
|
|
* @var string label to be displayed in the [[header|header cell]] and also to be used as the sorting |
|
|
|
|
|
|
|
* link label when sorting is enabled for this column. |
|
|
|
|
|
|
|
* If it is not set and the models provided by the GridViews data provider are instances |
|
|
|
|
|
|
|
* of [[ActiveRecord]], the label will be determined via [[ActiveRecord::getAttributeLabel()]]. |
|
|
|
|
|
|
|
* Otherwise [[yii\helpers\Inflector::camel2words]] will be used to get a label. |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public $label; |
|
|
|
|
|
|
|
/** |
|
|
|
* @var \Closure an anonymous function that returns the value to be displayed for every data model. |
|
|
|
* @var \Closure an anonymous function that returns the value to be displayed for every data model. |
|
|
|
* If this is not set, `$model[$attribute]` will be used to obtain the value. |
|
|
|
* If this is not set, `$model[$attribute]` will be used to obtain the value. |
|
|
|
*/ |
|
|
|
*/ |
|
|
@ -46,6 +54,11 @@ class DataColumn extends Column |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public $enableSorting = true; |
|
|
|
public $enableSorting = true; |
|
|
|
/** |
|
|
|
/** |
|
|
|
|
|
|
|
* @var array the HTML attributes for the link tag in the header cell |
|
|
|
|
|
|
|
* generated by [[Sort::link]] when sorting is enabled for this column. |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public $sortLinkOptions = array(); |
|
|
|
|
|
|
|
/** |
|
|
|
* @var string|array|boolean the HTML code representing a filter input (e.g. a text field, a dropdown list) |
|
|
|
* @var string|array|boolean the HTML code representing a filter input (e.g. a text field, a dropdown list) |
|
|
|
* that is used for this data column. This property is effective only when [[GridView::filterModel]] is set. |
|
|
|
* that is used for this data column. This property is effective only when [[GridView::filterModel]] is set. |
|
|
|
* |
|
|
|
* |
|
|
@ -59,39 +72,37 @@ class DataColumn extends Column |
|
|
|
|
|
|
|
|
|
|
|
protected function renderHeaderCellContent() |
|
|
|
protected function renderHeaderCellContent() |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
if ($this->header === null) { |
|
|
|
$provider = $this->grid->dataProvider; |
|
|
|
$provider = $this->grid->dataProvider; |
|
|
|
if ($this->attribute !== null && $this->enableSorting && |
|
|
|
|
|
|
|
($sort = $provider->getSort()) !== false && $sort->hasAttribute($this->attribute)) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$label = $this->getHeaderLabel(); |
|
|
|
if ($this->label === null) { |
|
|
|
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(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected function getHeaderLabel() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
$provider = $this->grid->dataProvider; |
|
|
|
|
|
|
|
if ($this->header !== null) { |
|
|
|
|
|
|
|
return $this->header; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if ($provider instanceof ActiveDataProvider && $provider->query instanceof ActiveQuery) { |
|
|
|
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); |
|
|
|
$label = $model->getAttributeLabel($this->attribute); |
|
|
|
} |
|
|
|
} else { |
|
|
|
$models = $provider->getModels(); |
|
|
|
$models = $provider->getModels(); |
|
|
|
if (($model = reset($models)) instanceof Model) { |
|
|
|
if (($model = reset($models)) instanceof Model) { |
|
|
|
/** @var Model $model */ |
|
|
|
/** @var Model $model */ |
|
|
|
return $model->getAttributeLabel($this->attribute); |
|
|
|
$label = $model->getAttributeLabel($this->attribute); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
$label = Inflector::camel2words($this->attribute); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
$label = $this->label; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ($this->attribute !== null && $this->enableSorting && |
|
|
|
|
|
|
|
($sort = $provider->getSort()) !== false && $sort->hasAttribute($this->attribute)) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return $sort->link($this->attribute, Html::encode($label), $this->sortLinkOptions); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
return Html::encode($label); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
return parent::renderHeaderCellContent(); |
|
|
|
} |
|
|
|
} |
|
|
|
return Inflector::camel2words($this->attribute); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected function renderFilterCellContent() |
|
|
|
protected function renderFilterCellContent() |
|
|
|