Limit The Number Of Caracters Displayed In Cgridview Cells
Posted 07 November 2012 - 06:01 AM
It would be great to have an option for a column in CgridView in order to give a maximum number of characters displayed in a cell. Moreover, if we can add "..." when this number is bigger, it's better.
Today, it's necessary to write a function which does the work.
Posted 07 November 2012 - 07:07 AM
'value' => 'strlen($data->columnName) > 5 ? substr($data->columnName, 0, 5)."..." : $data->columnName'
Posted 08 November 2012 - 07:48 AM
Posted 08 November 2012 - 08:11 AM
You can extend CGridView, CDataColumn classes yourself and rewrite CGridView::initColumns(), CDataColumn::renderDataCellContent() methods. There is line in the CGridView::initColumns() method where CDataColumn instantiation happens. Text shortening can be made in the CDataColumn::renderDataCellContent() method.