Limit a CGridView field to some preset length.

Comparing #3 with #5

Revision #5 was created by le_top le_top on Mar 24, 2013, 12:31:32 PM.

Update to handle multibyte UTF8 characters and improved tooltip encoding.

Content

[...]
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'=>$retvalue),CHtml::encode(mb_substr($value,0,$this->shortTextLimit-3).'...'),Yii::app()->charset).'...'));
 
        } else {
 
            $retval=CHtml::encode($value
);
}
return $retval;
}
}
```
[...]