在GridView中阅读更多链接

时间:2013-09-11 12:35:12

标签: html gridview yii yii-booster

我正在使用gridview来显示一组数据。一切正常,但我对如何在gridview中实现read more链接没有任何线索。下面是视图的代码,我使用的是Yiibooster TbGridView,但CGridview的代码也几乎相同。

<?php $this->widget('bootstrap.widgets.TbGridView', array(
    'dataProvider'=>$dataProvider,
    'columns'=>array(
         'startdate'
         'status',
          'description',
         array(
        'htmlOptions' => array('nowrap'=>'nowrap'),
        'class'=>'bootstrap.widgets.TbButtonColumn',
        'template' => '{view},{update}',
            'viewButtonUrl'=>'Yii::app()->createUrl("status/view",$params=array("id"=>$data["id"]))',
            'updateButtonUrl'=>'Yii::app()->createUrl("status/update",$params=array("id"=>$data["id"]))',
    )
    )))
    ?>

在这里,我不想显示完整的描述,而是显示它的子字符串以及一个名为“read more”的按钮,用户可以单击该按钮来显示整个“描述”。关于如何实施它的任何想法?

2 个答案:

答案 0 :(得分:2)

<?php $this->widget('bootstrap.widgets.TbGridView', array(
'dataProvider'=>$dataProvider,
'columns'=>array(
     'startdate'
     'status',
      array(
            'name' => 'description'
            'value' => 'substr($data->description,0,100)."...<div class=more-data>$data->description</div><a href=javascript:void(0); id=readMore>Read More</a>',
            'type' => 'raw',
        ),
     array(
    'htmlOptions' => array('nowrap'=>'nowrap'),
    'class'=>'bootstrap.widgets.TbButtonColumn',
    'template' => '{view},{update}',
        'viewButtonUrl'=>'Yii::app()->createUrl("status/view",$params=array("id"=>$data["id"]))',
        'updateButtonUrl'=>'Yii::app()->createUrl("status/update",$params=array("id"=>$data["id"]))',
)
)))
?>

不要担心html标签属性的引用。它将自动添加到浏览器中。之后做一些css调整

<style type='text/css'>
 .more-data{ display:none}
</style>

然后使用jquery点击名为read more的锚标记,你可以为这个div制作显示块,或者可以放任何你想要的效果。

它可以帮到你

答案 1 :(得分:1)

试试这个

<?php $this->widget('bootstrap.widgets.TbGridView', array(
'dataProvider'=>$dataProvider,
'columns'=>array(
     'startdate'
     'status',
     array(
                'value' => 'Model::function($data->description)',
                'type' => 'raw',
                'name' => 'description'
            ),
     array(
    'htmlOptions' => array('nowrap'=>'nowrap'),
    'class'=>'bootstrap.widgets.TbButtonColumn',
    'template' => '{view},{update}',
        'viewButtonUrl'=>'Yii::app()->createUrl("status/view",$params=array("id"=>$data["id"]))',
        'updateButtonUrl'=>'Yii::app()->createUrl("status/update",$params=array("id"=>$data["id"]))',
)
)))
?>

使用该模型中的函数更改模型名称和函数,并传递适当的参数。

然后在该函数中使用substr()并添加一个链接到完整描述可用的页面并返回整个字符串