In the List view of yii, i want to show a checkbox for each data item. At the top of have a checkbox. When check the top checkbox i want to check all checkbox in list. How it done in yii? Whats the script for this.?
index.php
<?php echo CHtml::form(); ?>
<?php echo CHtml::checkBox("main",false,array('value'=>'','id'=>'check1')); ?>
<?php $this->widget('zii.widgets.CListView', array(
'dataProvider'=>$dataProvider,
'itemView'=>'_view',
'template' => '{items}{pager}',
)); ?>
<?php echo CHtml::endForm(); ?>
_view.php
<div>
<?php echo CHtml::checkBox("abc[]",false,array('value'=>$data->message_id,'id'=>'sub')); ?>
<?php echo $data->body; ?>
</div>
Need the client script.
Thanks.
hiral23790
(Hiraldarji237)
April 10, 2013, 12:41pm
2
<script>
$(function () {
$('#check1').click(function () {
$(this).parents('fieldset:eq(0)').find(':checkbox').attr('checked', this.checked);
});
});
</script>
haymps
(Peter Hayman)
April 10, 2013, 1:32pm
3
in CGirdView the selectableRows=>2 allows you to check multiple boxes and it puts a check all box at the top.
<?php $this->widget('zii.widgets.grid.CGridView', array (
'id'=>'user-role-grid',
'dataProvider'=>$dataprovider,
'columns'=>array(
array('header' => 'Roles',
'value' => '$data->name',
'htmlOptions'=>array('width:25'),
),
array ('class'=>'CCheckBoxColumn',
'id'=>'check-boxes',
'value'=>'$data->role_id',
'htmlOptions'=>array('width:15; text-align: center;'),
'checked'=>'$data->checkbox',
'selectableRows'=>2,
),
),
));
?>
sasingh
(Sasingh01)
October 17, 2013, 5:16pm
4
I was looking for the solution to this problem and the solution posted by haymps saved me . Thank you !!