tanuja90
tanuja90

Reputation: 127

How to disable few check boxes in a CheckBoxList in Yii?

I am using CHtml::checkBoxList in my Yii application. I need to disable few checkboxes based on some criteria. How can I do that using Yii itself?

Below is my code

echo CHtml::checkBoxList('sid','',$posts1, array('id'=>'1','template' => '{input}{label}</td></tr><tr><td width="10%" style="padding:0 0 10px 20px;" class="rbr">','checkAll' => 'All'));

This will generate a table similar to the image below

enter image description here

What I need is to disable the checkbox corresponding to the first row. i.e., the check box with 4X-B in its row.

Any help in this regard will be highly appreciated.

Upvotes: 0

Views: 1636

Answers (2)

Double H
Double H

Reputation: 4160

create an Action as

 public function actionIndex() {

    $model= new CActiveDataProvider('ModelClass');

    $this->render('index',array('model' => $model));

}

In Index.php view file

<?php 

$this->widget('zii.widgets.grid.CGridView', array(
'dataProvider' => $model,
'columns' => array(
    array(
        'class' => 'CCheckBoxColumn',
        'disabled' => '$data->last_column=="4X-B" ? true : false',
    ),
    'country',
    'last_column'
)
));
?>

Read CGridView

Upvotes: 0

Danila Ganchar
Danila Ganchar

Reputation: 11302

It is impossible using CHtml class. You can create custom Html class. Or use foreach to generate html.

Upvotes: 1

Related Questions