zoukankan      html  css  js  c++  java
  • yii在TbGridView的td里面加入相应的下拉选项(转)

    当你需要在一个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' => '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' => '40px;'),
            ),

            array(
                'name' => 'file_size',
                'header' => '大小',
                'value' => 'TFileUtil::getFileSize($data->file_size)',
                'headerHtmlOptions' => array('style' => '80px;'),
            ),
            array(
                'name' => 'update_time',
                'header' => '修改时间',
                'value' => 'date("Y-m-d H:i:s", $data->update_time)',
                'headerHtmlOptions' => array('style' => '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' => '80px;text-align:center;', 'class' => 'notopen'),
                'headerHtmlOptions' => array('style' => '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

  • 相关阅读:
    LeetCode 230. 二叉搜索树中第K小的元素(Kth Smallest Element in a BST)
    LeetCode 216. 组合总和 III(Combination Sum III)
    LeetCode 179. 最大数(Largest Number)
    LeetCode 199. 二叉树的右视图(Binary Tree Right Side View)
    LeetCode 114. 二叉树展开为链表(Flatten Binary Tree to Linked List)
    LeetCode 106. 从中序与后序遍历序列构造二叉树(Construct Binary Tree from Inorder and Postorder Traversal)
    指针变量、普通变量、内存和地址的全面对比
    MiZ702学习笔记8——让MiZ702变身PC的方法
    你可能不知道的,定义,声明,初始化
    原创zynq文章整理(MiZ702教程+例程)
  • 原文地址:https://www.cnblogs.com/wgx214/p/3670518.html
Copyright © 2011-2022 走看看