【问题标题】:Readmore link in GridViewGridView 中的阅读更多链接
【发布时间】:2013-09-11 12:35:12
【问题描述】:

我正在使用 gridview 来显示一组数据。一切正常,除了我不知道如何在 gridview 中实现阅读更多链接。下面是视图的代码,我使用的是 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"]))',
    )
    )))
    ?>

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

【问题讨论】:

    标签: html gridview yii yii-booster


    【解决方案1】:
    <?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 制作显示块,或者可以放置您想要的任何效果。

    对你有帮助吗

    【讨论】:

      【解决方案2】:

      试试这个

      <?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() 并添加一个指向完整描述可用页面的链接并返回整个字符串

      【讨论】:

        猜你喜欢
        • 2015-02-04
        • 1970-01-01
        • 2012-11-01
        • 2013-03-25
        • 2017-02-21
        • 2016-11-12
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多