首页 > php教程 > php手册 > 正文

yii_wiki_204_using-cjuidialog-to-edit-rows-in-a-cgridview(通过

php中文网
发布: 2016-06-13 10:58:54
原创
944人浏览过

/*** 
Using CJuiDialog to edit rows in a CGridView   
 
http://www.yiiframework.com/wiki/204/using-cjuidialog-to-edit-rows-in-a-cgridview 
 
translated by php攻城师 
 
http://blog.csdn.net/phpgcs 
 
Scenario 
Solution 
Column hyperlink 
Javascript function 
 
**/  
  
/*** 
背景      Scenario 
***/   
  
我这里有一个 一系列的 clients/events 所属的 CGridView , 对每一行 (eventClient), 我想要实现快速的编辑 eventClient对话框。  
  
我的方法基于 这篇wiki http://www.yiiframework.com/wiki/145/cjuidialog-for-create-new-model/  
  
/*** 
 
解决方法  Solution  
 
***/  
  
首先基于 wiki 145 做了所有工作后, 再来 修改我们 的CGridView:  
  
Column hyperlink   
  
对每一列 , 在js 函数中设置 _updateComment_url 属性 为需要的 url。  
  
array(  
    'name'=>'comment',  
    'header'=>'Comments',  
    'type'=>'raw',  
    'value'=>'CHtml::link(  
        ($data["comment"]?$data["comment"]:"(comment)"),  
        "",  
        array(  
            \'style\'=>\'cursor: pointer; text-decoration: underline;\',  
            \'onclick\'=>\'{  
                updateComment._updateComment_url="\'.  
                    Yii::app()->createUrl(  
                        "eventClient/updateComment",  
                        array("id"=>$data["id"])  
                    )  
                .\'";  
                updateComment();  
                $("#dialogComment").dialog("open");}\'  
            )  
        );',  
),  
  
  
Javascript function   
  
在同一个页面我们将 调用这个 动作的 updateComment() 方法包含进来。   
  
<script type="text/javascript">  
   
function updateComment()  
{  
    // public property  
    var _updateComment_url;  
   
    <?php echo CHtml::ajax(array(  
        'url'=>'js:updateComment._updateComment_url',  
        'data'=> "js:$(this).serialize()",  
        'type'=>'post',  
        'dataType'=>'json',  
        'success'=>"function(data)  
            {  
                if (data.status == 'failure')  
                {  
                    $('#dialogComment div.divComment').html(data.div);  
                    // Here is the trick: on submit-> once again this function!  
                    $('#dialogComment div.divComment form').submit(updateComment);  
                }  
                else  
                {  
                    $('#dialogComment div.divComment').html(data.div);  
                    setTimeout(\"$('#dialogComment').dialog('close') \",2000);  
   
                    // Refresh the grid with the update  
                    $.fn.yiiGridView.update('event-client-grid');  
                }  
   
        } ",  
    ))?>;  
    return false;  
   
}  
   
</script>  
登录后复制

 

最佳 Windows 性能的顶级免费优化软件
最佳 Windows 性能的顶级免费优化软件

每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号