Hi my friends:
I get some problem, anyone can help me?I found many topics in forums but still not sloved.
I use CCeckBoxColumn on every row of the items on grid list view,the code is:
view: email/search
<?php $this->widget('zii.widgets.grid.CGridView', array(
'dataProvider'=>$search->search(),
'summaryText'=>Yii::t('email','结果:{start}-{end} of {count}'),
'selectableRows'=>2,
'columns'=>array(
array(
'class'=>'myCheckBoxColumn',
'id'=>$search->email_id,
'visible'=>(Yii::app()->user->getState("role")) == User::ADMIN,
'checked'=>'(in_array($data->email_id,Yii::app()->session["ids"]))?true:false',
),
'email_date',
'email_from',
'email_to',
'email_theme',
));
?>
<?php $this->endWidget(); ?>
In order to use CGriedViews selection feature,i add a little javascript to get the current selection any time(eg: when user click someone checkbox).The javascript in the view ‘email/search’ .
<script type="text/javascript">
$(document).ready(function(){
$("[name='yw1_c0[]']").click(function(){
alert(this.id);
var id = this.id;
$.ajax({
async:false,
url:'http://localhost/email/index.php?r=email/search',
type:'GET',
data:'ids='+id,
dataType:'text',
timeout:1000,
error:function(){
alert('Error!');
},
success:function(){
alert('success!');
}
});
});
});
</script>
<?php $this->widget('zii.widgets.grid.CGridView', array(
'dataProvider'=>$search->search(),
'summaryText'=>Yii::t('email','结果:{start}-{end} of {count}'),
'selectableRows'=>2,
'columns'=>array(
array(
'class'=>'myCheckBoxColumn',
'id'=>$search->email_id,
'visible'=>(Yii::app()->user->getState("role")) == User::ADMIN,
'checked'=>'(in_array($data->email_id,Yii::app()->session["ids"]))?true:false',
),
'email_date',
'email_from',
'email_to',
'email_theme',
));
?>
<?php $this->endWidget(); ?>
Controller:email/search
public function actionSearch(){
print_r($_GET['ids']);
Yii::app()->session['ids'] = array(123,234,236);
$search = new Email('search');
$folder_object = new Folder;
$folder_models = Folder::model()->findAll();
if(count($folder_models) != 0){
foreach($folder_models as $folder_model){
$folder[$folder_model->folder_id] = $folder_model->folder_name;
}
}else{
$folder = array();
}
$this->render('search',array('search'=>$search,'folder'=>$folder));
}
In the controller use $_GET[‘ids’] can not get id of selected checkbox,is wrong:
Undefined index: ids
Thanks for help!