If you would like to have custom HTML and still original sorting functionality, you can create own DataColumn (let's say in common/components), then in grid view set dataColumnClass
:
<?= GridView::widget([
...
'dataColumnClass' => 'common\components\HtmlDataColumn',
'columns' => [
'id',
[
'attribute' => 'title',
'htmlHeader' => 'Some Header<span class="glyphicon glyphicon-ok"></span>',
],
...
My DataColumn:
namespace common\components;
use yii\helpers\Html;
/**
* DataColumn that allows HTML in 'header' yet still appends sorting.
*/
class HtmlDataColumn extends \yii\grid\DataColumn
{
public $htmlHeader = null;
/**
* @inheritdoc
*/
protected function renderHeaderCellContent()
{
if ($this->header !== null || $this->label === null && $this->attribute === null) {
return parent::renderHeaderCellContent();
}
if ($this->htmlHeader !== null) {
$label = $this->htmlHeader;
} else {
$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;
}
}
Hope this helps.