mirror of
https://github.com/yiisoft/yii2.git
synced 2025-08-13 22:06:51 +08:00
Added encodeLabel param to \yii\grid\DataColumn
Use case: ``` echo GridView::widget([ ... 'columns' => [ ... [ 'attribute' => 'created_at', 'label' => '<span data-toggle="tooltip" class="glyphicon glyphicon-time" title="'.Yii::t('app', 'Created At').'"></span>', 'encodeLabel' => false, ... ], ```
This commit is contained in:

committed by
Qiang Xue

parent
cfe874607f
commit
c6cb205653
@ -49,6 +49,10 @@ class DataColumn extends Column
|
||||
* Otherwise [[\yii\helpers\Inflector::camel2words()]] will be used to get a label.
|
||||
*/
|
||||
public $label;
|
||||
/**
|
||||
* @var boolean whether the label should be HTML-encoded.
|
||||
*/
|
||||
public $encodeLabel = true;
|
||||
/**
|
||||
* @var string|\Closure an anonymous function that returns the value to be displayed for every data model.
|
||||
* The signature of this function is `function ($model, $key, $index, $column)`.
|
||||
@ -128,9 +132,9 @@ class DataColumn extends Column
|
||||
|
||||
if ($this->attribute !== null && $this->enableSorting &&
|
||||
($sort = $provider->getSort()) !== false && $sort->hasAttribute($this->attribute)) {
|
||||
return $sort->link($this->attribute, array_merge($this->sortLinkOptions, ['label' => Html::encode($label)]));
|
||||
return $sort->link($this->attribute, array_merge($this->sortLinkOptions, ['label' => ($this->encodeLabel ? Html::encode($label) : $label)]));
|
||||
} else {
|
||||
return Html::encode($label);
|
||||
return $this->encodeLabel ? Html::encode($label) : $label;
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user