Yii 1.1: checkBox in CGridview

2 followers

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();
 
        }
    }

Total 1 comment

#20052 report it
pinnama at 2017/03/20 03:21am
error where using explode method

Controller section will throw error. because explode allows second parameter as string and array is given. Use implode instead of explode

$arr = implode(',', $_REQUEST['selectedIds']);

Leave a comment

Please to leave your comment.