checkBox in CGridview

You are viewing revision #2 of this wiki article.
This version may not be up to date with the latest version.
You may want to view the differences to the latest version.

next (#3) »

some when you need to add checkbox in cgridview and change state of selected rows by additianal parameters. in view :

<div >
<?php 

    echo '  <span>change status to :<span>'.CHtml::dropDownList('newStatus', 0,CHtml::listData($model,'code_item_id','code_item_name'),array('prompt'=>'select status' ));

    echo CHtml::ajaxLink("edit", $this->createUrl('report/getvalue'), array(
        "type" => "post",
        "data" => 'js:{theIds : $.fn.yiiGridView.getChecked("show-list","selectedIds").toString(),"status":$("#newStatus").val()}',
        "success" => 'js:function(data){ $.fn.yiiGridView.update("show-list")  }' ),array(
        'class' => 'btn btn-info'
        )
        );
   

?>
</div>


<div id="tab_content" >

    <?php

    $this->widget('zii.widgets.grid.CGridView',array(
        'id' => 'show-list',
        'dataProvider' => $model->search(),
        
        'columns'=> array(
            array(
                'name' => 'check',
                'id' => 'selectedIds',
                'value' => '$data->order_id',
                'class' => 'CCheckBoxColumn',
                'selectableRows' => '100',
                
            ),
            array(
            'name' =>  'order_id',
            'value' => '$data->order_id',
            ),
          
            array(
                'name' =>  'order_total',
                'value' => '$data->order_total',
            ),
            
            
        )
    ));
     
    
     
            ?>
</div>


in controller :

public function actionGetValue(){
        
        $arr = explode(',', $_POST['theIds']);
        $criteria = new CDbCriteria;
        $criteria->addInCondition('order_id' ,$arr );
        $model = PurchaseOrders::model()->findAll($criteria);
        foreach ($model as $value) {
            //update Order`s Status
            $value->code_item_last_state_id = $_POST['status'];
            $value->update();
            
        }
    }