zoukankan      html  css  js  c++  java
  • YIi gridview 自定义按按钮

    我们在用表格展示数据并管理的时候,可能会需要用到按钮来操作某一行数据,比如查看,修改,删除!

    Yii内置了3种按钮:查看,修改和删除,你可以自定义样式、事件。详细配置见类参考:CButtonColumn.

    如果需要自定义按钮绑定指定的事件该怎么办呢?

    幸运的是Yii提供了自定义按钮的办法.看代码:

    在视图文件里面:

     

    Php代码 复制代码 收藏代码
    1. $this->widget('zii.widgets.grid.CGridView'array(   
    2.     'id'=>'xx-xx-grid',   
    3.     'dataProvider'=>$model->search(),   
    4.     'filter'=>$model,   
    5.     'pager'=>array(   
    6.             'class'=>'CLinkPager',   
    7.             'nextPageLabel'=>'下一页',   
    8.             'prevPageLabel'=>'上一页',   
    9.             'header'=>'',   
    10.     ),   
    11.     'summaryText'=>'<font color=#0066A4>显示{start}-{end}条.共{count}条记录,当前第{page}页</font>',   
    12.     'columns'=>array(   
    13.         array(   
    14.                 'name'=>'id',   
    15.                 'htmlOptions'=>array('width'=>'25'),   
    16.                 'sortable'=>false,   
    17.         ),   
    18.         array(   
    19.             'class'=>'CButtonColumn',   
    20.             'template'=>'{view} {update}',   
    21.             'viewButtonOptions'=>array('title'=>'查看'),   
    22.             'updateButtonOptions'=>array('title'=>'修改'),   
    23.         ),   
    24.         array(   
    25.             'class'=>'CButtonColumn',   
    26.             'header'=>'首页展示',   
    27.             'template'=>'{add} {del}',   
    28.             'buttons'=>array(   
    29.                     'add' => array(   
    30.                             'label'=>'展示',     // text label of the button   
    31.                             'url'=>'Yii::app()->controller->createUrl("focus/create",array("id"=>$data->primaryKey,"type"=>1))',       // a PHP expression for generating the URL of the button   
    32.                             'imageUrl'=>'http://s.maylou.com/common/images/ysh.jpg',  // image URL of the button. If not set or false, a text link is used   
    33.                             'options'=>array('style'=>'cursor:pointer;'), // HTML options for the button tag   
    34.                             'click'=>$click,     // a JS function to be invoked when the button is clicked   
    35.                             'visible'=>'SiteRecommend::isItemInTypeAndId(1, $data->id)?false:true',   
    36.                     ),   
    37.                     'del' => array(   
    38.                             'label'=>'取消展示',     // text label of the button   
    39.                             'url'=>'Yii::app()->controller->createUrl("focus/delete",array("id"=>$data->primaryKey,"type"=>1))',       // a PHP expression for generating the URL of the button   
    40.                             'imageUrl'=>'http://s.maylou.com/common/images/yzhu.jpg',  // image URL of the button. If not set or false, a text link is used   
    41.                             'options'=>array('style'=>'cursor:pointer;'), // HTML options for the button tag   
    42.                             'click'=>$click,     // a JS function to be invoked when the button is clicked   
    43.                             'visible'=>'SiteRecommend::isItemInTypeAndId(1, $data->id)?true:false',   
    44.                     )   
    45.             ),   
    46.         ),   
    47.     ),   
    48. ));  
  • 相关阅读:
    Unsupported major.minor version 51.0(JDK版本错误)
    String、StringBuilder和StringBuffer的区别
    循环依赖常问问题,spring三级缓存解决循环依赖解析图
    ens33网卡失效ipaddr查询不到ip: 出现:ens33: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000 link/ether 00:0c:29:2c:8d:e1 brd ff:ff:ff:ff:ff:ff
    redis被攻击,导致redis连接不上,RDB异常解决方案
    项目集成seata和mybatisplus冲突问题解决方案:(分页插件失效, 自动填充失效, 自己注入的id生成器失效 找不到mapper文件解决方案)
    seata服务端搭建和客户端配置(使用nacos进行注册发现,使用mysql进行数据持久化),以及过程中可能会出现的问题与解决方案
    通过串口(蓝牙WiFi)与Arduino通信
    Python callable函数判断某个对象是否可调用
    Python 通过PyUserInput模拟键鼠操作
  • 原文地址:https://www.cnblogs.com/xiongsd/p/3127882.html
Copyright © 2011-2022 走看看