Adding 'disabled' to CCheckBoxColumn and support for yiigridview.js

You are viewing revision #2 of this wiki article.
This version may not be up to date with the latest version.
You may want to view the differences to the latest version.

next (#3) »

I recently had to have a checkbox column in my grid view that supported the 'disabled' attribute. This was easy enough to do by extending the CCheckBoxColumn. Hwoever, I also wanted the checkbox to be selected when clicking on the table's row (supported via CGridView's selectableRows option). I discovered I had to tweak yiigridview.js so that it would not select disabled rows when clicking on it or clicking on the 'select all' checkbox.


Save this file to protected/extensions/. This was taken directly from


class ECheckBoxColumn extends CCheckBoxColumn
        public $disabled;
        protected function renderDataCellContent($row,$data)

Cop this file and related files (css, img, etc) to /protected/assets/gridview/ or where ever you want it (if different, be sure to change it in the usage scenerio). I'm just going to link the whol efile here:

$this->widget('bootstrap.widgets.TbGridView', array(
	'baseScriptUrl' => Yii::app()->getAssetManager()->publish(Yii::getPathOfAlias('app.assets')).'/gridview',
	'rowCssClassExpression' => '(expresion) ? null : "disabled"',
			'checked' => '('.$char[0]->activeAPIMask.' & '.$availableMask.' & $data->mask)',
            'disabled'=>'(true/false exression (same as rowCssClassExpression)',
Your code here...

'disabled' class is hard coded into the modified JS code. For me to add a custom 'disabled' class, I would have to extend CGridView, and to me it just wasn't worth adding a small property for it to be passed into yiigridview.js.