【问题标题】:Yii CGridview checkbox ajax database updationYii CGridview 复选框 ajax 数据库更新
【发布时间】:2013-03-23 13:47:31
【问题描述】:

我在yii cgridview中列出了三个项目,每一行都有一个复选框,点击当前行项目的状态应该在数据库中更新。请提供一些实现这一点的想法。

【问题讨论】:

    标签: php ajax yii cgridview


    【解决方案1】:

    您可以使用 cgridview 列数组的 ajax 属性。请在下面找到示例。

        array(
            'header'=>'Status',
            'type'=>'raw',
            'value'=>'CHtml::CheckBox("$data->active",$data->active,array(
             "ajax" => array(
                        "type"=>"POST", 
                        "url"=> ApplicationConfig::getURL("user", "twitterFeed", "changeStatus",array("feed_id"=>$data->feed_id)),
                        "dataType"=>"text",
                        "data" => array("ap_programType_id" => $data->feed_id),
                        "success" => "js:function(html){
                               if(html==\"1\"){
                                   $(\"#active$data->feed_id\").attr(\"checked\",\"checked\");
                                   window.location.reload()
                               }
                                   else if(html==\"0\"){
                                   $(\"#active$data->feed_id\").attr(\"checked\",false);
                                   window.location.reload()
                               }
    
                        }",
                        "error"=>"function (xhr, ajaxOptions, thrownError){
                                alert(xhr.statusText);
                                alert(thrownError);}",
                ),
            "style"=>"width:50px;","feed_id"=>$data->feed_id,"id"=>"active".$data->feed_id))',
            'htmlOptions'=>array("width"=>"50px"),
        ),  
    

    【讨论】:

    • 整洁!...嘿,我想知道您是否可以提供文档链接?...以供将来参考
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-07
    • 2014-09-05
    • 2023-04-10
    • 1970-01-01
    相关资源
    最近更新 更多