Handle The Long Content In Cgridvview By Abbr Tag

Another trick for the CGridView is create abbr column. Other topics related to CGridView, can search key word "CGridView".

In most case, the client would like to show long columns in CGridView, so it makes CGridView oversize, below is a quick way to show briefly content in that columns (For example, only first 12 characters), which will save a lot of space to show more columns in one view.

Below is a screen shot, shows hot it works.

4887

cgridviewabbr.png

And code is here:




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

...

'columns'=>array(

...

array(

			'name'=>'bid_name',

			'type'=>'html',

			'value'=>'"<abbr title=\'".$data->bid_name."\'>".substr($this->bid_name, 0, 12)."...</abbr>"',			

		),

...



Now it make 60 characters into 12 characters, and when you mouse move over then it will show whole text in 60 characters.

Hi

That’s a good trick and you can read in my Wiki article how to further abstract it in a formatter:

http://www.yiiframework.com/wiki/454/limit-a-cgridview-field-to-some-preset-length/

Yes, that’s full functional converter.

Thanks!