我有网格
<?php $this->widget('bootstrap.widgets.TbGridView',array(
'id'=>'products-grid',
'htmlOptions'=>array('class'=>'grid-view table-striped',),
'dataProvider'=>$model->search(),
'columns'=>$columns,
)); ?>
$ model-&gt; search()
return new CActiveDataProvider($this, array(
'criteria' => $criteria,
'pagination' => array('pageSize' => 50)
));
我需要限制每列的长度。例如,如果第1列具有值
第一列的“Hello World”
和配置变量是7,然后我需要渲染
“你好......”
我想,我可以用行为来解决我的问题,对吗?拜托,帮助我!
答案 0 :(得分:1)
将搜索功能更改为此...不确定是否为最快
public function search(){
$returnarray = array();
$dataset = new CActiveDataProvider($this, array(
'criteria' => $criteria,
'pagination' => array('pageSize' => 50)
));
foreach($dataset as $ds){
$returnarray['your_table_index'] = (strlen($ds->your_element) > 8) ? substr($ds->your_element,0,7).'...' : $ds->your_element;
}
return $returnarray;
}
答案 1 :(得分:1)
foreach($columns as &$column)
{
if($column['name'] == 'number')
{
$column['value'] = 'strlen($data->number) > 14 ? substr($data->number, 0, 14)."..." : $data->number';
}
}