• 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. ));  
  • 相关阅读:
    vscode 自动换行 关闭
    QGIS geojson 矢量操作 稀释 抽稀 压缩 边界抽稀
    vscode 关闭烦人的 tooltip 提示
    sql函数汉字转拼音
    sql 排名函数
    客户端文件下载 download.js
    Oracle 创建 DBLink 的方法
    RDLC分组序号
    sql server中使用函数验证身份证号码是否合法
    oracle导出数据库exp时报错,ORA12154 TNS: 无法解析指定的连接标识符
  • 原文地址:https://www.cnblogs.com/xiongsd/p/3127882.html
Copyright © 2020-2023  润新知