当你需要在一个GridView渲染某一个复杂元素的时候(特别是在这种情况下,这是一个小部件),这就需要你在控制器中调用一个动作。例如你给一个GridView的定义这样的一列:

<?php

$this->widget('bootstrap.widgets.TbGridView', array(
    'id' => 'folder-grid',
    'dataProvider' => $model->search($folder_id),
    'template' => "{items}{pager}",
    'rowHtmlOptionsExpression' => 'array("file_id"=>$data->file_id, "file_name"=>rtrim($data->file_name,".".$data->file_ext), "file_ext"=>$data->file_ext)',
    'columns' => array(
        array(
            'selectableRows' => 2,
            'class' => 'CCheckBoxColumn',
            'headerHtmlOptions' => array('width' => '10px'),
            'htmlOptions' => array('class' => 'notopen'),
            'checkBoxHtmlOptions' => array('name' => 'ids[]'),
        ),
        array(
            'name' => 'folder_id',
            'headerHtmlOptions' => array('style' => 'display:none'),
            'htmlOptions' => array('style' => 'display:none;'),
        ),
        array(
            'name' => 'file_name',
            'header' => '文件名',
            'type' => 'raw',
            'headerHtmlOptions' => array('style' => 'width:100%;'),
            'htmlOptions' => array('class' => 'ellipsis'),
            'value' => 'CHtml::openTag("img", array("src" => TFileUtil::getFileTypeIcon($data->file_name,true),"style"=>"margin-right:4px")) . rtrim($data->file_name,".".$data->file_ext)',
        ),
        array(
            'name' => 'more_opt',
            'header' => '',
            'value' => array($this, 'renderButtons'),
            'sortable' => false,
            'htmlOptions' => array('class' => 'more notopen'),
            'headerHtmlOptions' => array('style' => 'width:40px;'),
        ),
        array(
            'name' => 'file_size',
            'header' => '大小',
            'value' => 'TFileUtil::getFileSize($data->file_size)',
            'headerHtmlOptions' => array('style' => 'width:80px;'),
        ),
        array(
            'name' => 'update_time',
            'header' => '修改时间',
            'value' => 'date("Y-m-d H:i:s", $data->update_time)',
            'headerHtmlOptions' => array('style' => 'width:160px;'),
        ),
        array(
            'class' => 'bootstrap.widgets.TbButtonColumn',
            'template' => '{update}{download}{remove}',
            'buttons' => array(
                'update' => array(
                    'label' => '',
                    'options' => array(
                        'class' => 'icon-update td-link-icon',
                        'data-toggle' => 'modal',
                        'data-target' => '#rename_file',
                        'title' => '修改',
                    ),
                    'click' => 'js:function(){ 
                         var $row = $(this).parents("tr");
                         var $column = $(this).parent("td").siblings();
                           var id = $column.eq(0).children("input").val();
                          $("#rename_file #FilePrivate_id").val(id);
                          $("#rename_file #FilePrivate_file_name").val($row.attr("file_name"))
                            .next().text("." + $row.attr("file_ext"));
                       }',
                ),
                'download' => array(
                    'label' => '',
                    'url' => 'Yii::app()->controller->createUrl("/file/private/download",array(
                    "id"=>$data->id,"fileId"=>$data->file_id,"fileName"=>FilePrivate::getFileName($data->id,$data->file_id), "createTime"=>$data->create_time))',
                    'options' => array(
                        'class' => 'download td-link-icon icon-download-2',
                        'title' => '下载',
                    ),
                ),
                'remove' => array(
                    'label' => '',
                    'options' => array(
                        'class' => 'icon-remove td-link-icon',
                        'data-toggle' => 'modal',
                        'data-target' => '#remove',
                        'title' => '删除',
                    ),
                    'click' => 'js:function(){ 
                         var $column = $(this).parent("td").siblings();
                         var id = $column.eq(0).children("input").val();
                          $("#remove #FilePrivate_id").val(id);
                          $("#remove h4").text("删除文件");       
                          $("#remove .note span:eq(1)").text("确定要删除所选的文件吗?");
                          $("#remove #removefiles").hide();
                          $("#remove #removefile").show();
                       }',
                ),
            ),
            'header' => '操作',
            'htmlOptions' => array('style' => 'width:80px;text-align:center;', 'class' => 'notopen'),
            'headerHtmlOptions' => array('style' => 'width:80px;text-align:center;'),
        ),
    )
));
?>

然后在控制器里面这么渲染

/**
     * 显示更多操作的按钮
     */
    public function renderButtons() {
        $this->widget('bootstrap.widgets.TbButtonGroup', array(
            'size' => 'small',
            'buttons' => array(
                array('label' => '', 'items' => array(
                        array('label' => '重命名', 'url' => 'javascript:;', 'linkOptions' => array('id' => 'renameFile')),
                        array('label' => '移动到', 'url' => 'javascript:;', 'linkOptions' => array('id' => 'moveFile')),
                        array('label' => '复制到', 'url' => 'javascript:;', 'linkOptions' => array('id' => 'copyFile'))
                )),
            ),
        ));
    }

就能够显示如下图显示的页面:
 

http://stackoverflow.com/questions/16352998/yii-bootstrap-widget-tbbuttoncolumn-widget-tbbuttongroup

yii在TbGridView的td里面加入相应的下拉选项(转)的更多相关文章

  1. Yii 1开发日记 -- 后台搜索功能下拉及关联表搜索

    Yii 1 实现后台搜索,效果如下: 一. 下拉搜索: 1.模型中和常规的一样 if (isset($_GET['agency']['status']) && $_GET['agenc ...

  2. yii框架中的下拉菜单和单选框

    yii中的下拉菜单: 第一种: <?= $form->field($model, 'parent_id')->dropDownList(ArrayHelper::map($data, ...

  3. Yii 生成表单下拉选框及查询下拉选框

    CHtml类参考: http://www.yiichina.com/api/CHtml#activeDropDownList-detail activeDropDownList() 方法 public ...

  4. yii NAV x下拉

    $menuItems[] = [ 'label' => "<img src='/images/small.jpg'>", 'url' => ['/site/ ...

  5. mydetails-yii1

    1.yii验证码多余的get a new code ,即使在main.php中配置了中文也是出现获取新图片,影响效果 需要把 <?php $this->widget('CCaptcha') ...

  6. sphinx的使用

    1.下载地址 http://sphinxsearch.com/downloads/release/ 2.将其解压到D:\sphinx,并在D:\sphinx下新建目录data(用来存放索引文件)与lo ...

  7. 很强大的HTML+CSS+JS面试题(附带答案)

    一.单项选择(165题) 1.HTML是什么意思? A)高级文本语言 B)超文本标记语言 C)扩展标记语言 D)图形化标记语言 2.浏览器针对于HTML文档起到了什么作用? A)浏览器用于创建HTML ...

  8. SharePoint 2013 扩展查阅项功能

    SharePoint 2013的查阅项功能,就是可以扩展其他列表字段为当前列表选项,但是选项太多的时候,会造成选择起来非常麻烦,所以,我们采取JS+Ajax的方式,改善一下这个展示,使操作更加方便. ...

  9. html5基础知识点

    1.WEB基础知识 1.WEB 与 Internet 1.Internet 互联网 若干台计算机 通过 网线 所连接而成的物理设备 主要服务: 1.Telnet 2.Email 3.WWW(Word ...

随机推荐

  1. isAnagram

    /*Given two strings s and t, write a function to determine if t is an anagram of s. For example, s = ...

  2. Android Eclipse 里面依赖工程无法关联源码解决方案

    android开发中,debug调试是一种非常实用快速定位问题的办法.eclipse中多工程依赖状态下会偶现无法debug的困扰,debug中的代码执行时会报出如下错误  The JAR of thi ...

  3. threading event

    #!usr/bin/env python 2 #coding: utf-8 3 #Author: Andy 4 5 import threading 6 import time 7 8 def pro ...

  4. Solr数据库连接之多表关联

    Solr环境配置好后,有很多时候我们需要把数据库里的数据添加到索引里,这时就需要配置跟数据库的连接,下面我们看配置的步骤. 1. 配置 solrconfig.xml  (在slor 主目录 core ...

  5. SQL必知必会笔记(1)

    去SQL AXDB 中Query数据 Open the SQL > Connect > Select AXDB > new Query select REFID, ITEMID, R ...

  6. [系统] 安装Ubuntu 双系统 - 失败

    因为工作原因, 所以需要装ubuntu系统. 在网络上查了一下, 一般都是使用U盘安装. 但是由于手头上既没有U盘又没有光盘,只能用硬盘安装了. 查一下, 使用wubi安装方式从硬盘安装, 非常方便. ...

  7. 004.ASP.NET MVC中的HTML Helpers

    原文链接:http://www.codeproject.com/Articles/794579/ASP-NET-MVC-HTML-Helpers-A-MUST-KNOW 1.什么是HTML Helpe ...

  8. c# 生成json数据包

    json数据类型,归根到底就是一个字符串,管他里面什么格式,它就是一个字符串来的! 看一个json数据包: { "touser":"OPENID", " ...

  9. MSP430推荐网站

    http://www.amobbs.com/thread-5092914-1-1.html http://www.amobbs.com/thread-4701106-1-1.html

  10. 洛谷P1470 最长前缀 Longest Prefix

    P1470 最长前缀 Longest Prefix 73通过 236提交 题目提供者该用户不存在 标签USACO 难度普及/提高- 提交  讨论  题解 最新讨论 求大神指导,为何错? 题目描述 在生 ...