Revision #5 has been created by le_top on Mar 24, 2013, 12:31:32 PM with the memo:
Update to handle multibyte UTF8 characters and improved tooltip encoding.
« previous (#3) next (#6) »
Changes
Title
unchanged
Limit a CGridView field to some preset length.
Category
unchanged
How-tos
Yii version
unchanged
Tags
unchanged
CGridView, width, column, tooltip
Content
changed
[...]
1) a) Create the formatter method:
```php
class YFormatter extends CFormatter {
/* @var int The text length limit for the ShortText formatter. */
public $shortTextLimit= 20;
/**
*
* Text formatter shortening long texts and displaying the full text[...]
*/
public function formatShortText($value) {
$retval=CHtml::encode($value);
if(strlen($value)>$this->shortTextLimit) {
$retval=CHtml::tag('span',array('title'=>$
retval
ue),CHtml::encode(
mb_substr($value,0,$this->shortTextLimit-3
).'...'),Yii::app()->charset).'...'));
} else {
$retval=CHtml::encode($value);
}
return $retval;
}
}
```[...]