Yii Framework Forum: Limit The Number Of Caracters Displayed In Cgridview Cells - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Limit The Number Of Caracters Displayed In Cgridview Cells Rate Topic: -----

#1 User is offline   Zugluk 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 205
  • Joined: 08-August 12

Posted 07 November 2012 - 06:01 AM

hello,

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.
0

#2 User is offline   CeBe 

  • Advanced Member
  • Yii
  • Group: Yii Dev Team
  • Posts: 482
  • Joined: 16-July 10
  • Location:Berlin. Germany

Posted 07 November 2012 - 07:07 AM

Why does a function not work? For a normal data column you can use an expression like

'value' => 'strlen($data->columnName) > 5 ? substr($data->columnName, 0, 5)."..." : $data->columnName'


http://www.yiiframew...mn#value-detail
0

#3 User is offline   Zugluk 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 205
  • Joined: 08-August 12

Posted 08 November 2012 - 07:48 AM

yep, you can indeed write a function like you said, and that's what I'm doing actually... but do it for every column is very boring... if there was an option in cgridview which took in account the number maximum of characters to display, it would be quicker and nicer than write array(name=>'...','value'=>'...') for every column.
0

#4 User is offline   resurtm 

  • Member
  • Yii
  • Group: Yii Dev Team
  • Posts: 83
  • Joined: 19-December 10

Posted 08 November 2012 - 08:11 AM

View PostZugluk, on 08 November 2012 - 07:48 AM, said:

yep, you can indeed write a function like you said, and that's what I'm doing actually... but do it for every column is very boring... if there was an option in cgridview which took in account the number maximum of characters to display, it would be quicker and nicer than write array(name=>'...','value'=>'...') for every column.


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.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users