You are viewing revision #3 of this wiki article.
This is the latest version of this article.
You may want to see the changes made in this revision.
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();
}
}
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']);
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.