1

I have three items listed in yii cgridview,each row has a checkbox there,on clicking the status of the current row item should be updated in the database.Please provide some ideas for achieving this.

enter image description here

1 Answer 1

2

You can user ajax property of cgridview columns array. Please find the example below.

    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"),
    ),  
Sign up to request clarification or add additional context in comments.

1 Comment

Neat!.. hey I wonder If you can provide the link to documentation ?... for future reference

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.