Capitalizing Cgridview Headers

Hi, we recently started on a Yii project and we have a requirement to capitalize all CGridView headers. We can do it by capitalizing attribute labels in the model, but it will not work for us since we need capitalization only in grids. Is there any work around for this?


you can do it manually for each column like that

<?php $this->widget('zii.widgets.grid.CGridView', array(





               array('header'=>'A Header',







)); ?>

'name' => 'firstname',

'header' => strtoupper($model->getAttributeLabel('firstname'))

or overwrite CDataColumn::renderHeaderCellContent()

Hi KonApaz and mbi,

Both solutions are working fine, but I found the second method mbi mentioned is more generic and appropriate for us. We have lot of views with Cgridviews and it is somewhat hard to change them one by one. Following is the overriden method.


protected function renderHeaderCellContent()


		if($this->grid->enableSorting && $this->sortable && $this->name!==null){                 	

                	$sort = $this->grid->dataProvider->getSort();

                	$label = strtoupper(isset($this->header) ? $this->header : $sort->resolveLabel($this->name));                	

                	echo $sort->link($this->name, $label, array('class'=>'sort-link'));


		elseif($this->name!==null && $this->header===null)


			if($this->grid->dataProvider instanceof CActiveDataProvider)				

                        	echo CHtml::encode(strtoupper($this->grid->dataProvider->model->getAttributeLabel($this->name)));


				echo CHtml::encode(strtoupper($this->name));





On a side note, currently we do not set ‘header’ parameter in gridviews. Is it ok to have it in this way in terms of Yii best practices?

Thank you.

Can’t CSS do it?

We tried CSS text-transform:uppercase, but it dose not work well with utf-8 characters.