checkBoxHtmlOptions in the CCheckBoxColumn not working.

checkBoxHtmlOptions not working in the CCheckBoxColumn


		<?php

		$this->widget('zii.widgets.grid.CGridView', array(

		    'id' => 'shipping-list',

		    'dataProvider' => $shipping,

		    'enablePagination'=>FALSE,

		    'summaryText'=>'',

            'columns'=>array(

                array( 'class'=>'CCheckBoxColumn',

				'value'=>'$data->shipping_id',

			'checkBoxHtmlOptions'=>array(

			 'name'=>'order[shipping_id]',

			)

                    ),

                'shipping_id',

                'shipping_name',

then generate the HTML:




<td class="checkbox-column"><input type="checkbox" id="shipping-list_c0_0" value="2" name="shipping-list_c0[]"></td>

but I wanna the name to be order[shipping_id]

it would be a bug for CCheckBoxColumn.

the CCheckBoxColumn now not providing a name htmloption for checkbox.

so I change the Class.




class CCheckBoxColumn extends CGridColumn

{

	/**

	 * @var string the attribute name of the data model. The corresponding attribute value will be rendered

	 * in each data cell as the checkbox value. Note that if {@link value} is specified, this property will be ignored.

	 * @see value

	 */

	public $name;

	/**

	 * @var string a PHP expression that will be evaluated for every data cell and whose result will be rendered

	 * in each data cell as the checkbox value. In this expression, the variable

	 * <code>$row</code> the row number (zero-based); <code>$data</code> the data model for the row;

	 * and <code>$this</code> the column object.

	 */

	public $value;

	/**

	 * @var array the HTML options for the data cell tags.

	 */

	public $htmlOptions=array('class'=>'checkbox-column');

	/**

	 * @var array the HTML options for the header cell tag.

	 */

	public $headerHtmlOptions=array('class'=>'checkbox-column');

	/**

	 * @var array the HTML options for the footer cell tag.

	 */

	public $footerHtmlOptions=array('class'=>'checkbox-column');

	/**

	 * @var array the HTML options for the checkboxes.

	 */

	public $checkBoxHtmlOptions=array();


	/**

	 * Initializes the column.

	 * This method registers necessary client script for the checkbox column.

	 */

	public function init()

	{

		//$name="{$this->id}\\[\\]";

		if (array_key_exists('name', $this->checkBoxHtmlOptions)){

		$name=$this->checkBoxHtmlOptions['name']; }

		$name="{$this->id}\\[\\]";

//above this changed by me <img src='http://www.yiiframework.com/forum/public/style_emoticons/default/smile.gif' class='bbc_emoticon' alt=':)' />


		if($this->grid->selectableRows==1)

			$one="\n\tjQuery(\"input:not(#\"+$(this).attr('id')+\")[name='$name']\").attr('checked',false);";

		else

			$one='';

		$js=<<<EOD

jQuery('#{$this->id}_all').live('click',function() {

	var checked=this.checked;

	jQuery("input[name='$name']").each(function() {

		this.checked=checked;

	});

});

jQuery("input[name='$name']").live('click', function() {

	jQuery('#{$this->id}_all').attr('checked', jQuery("input[name='$name']").length==jQuery("input[name='$name']:checked").length);{$one}

});

EOD;

		Yii::app()->getClientScript()->registerScript(__CLASS__.'#'.$this->id,$js);

	}


	/**

	 * Renders the header cell content.

	 * This method will render a checkbox in the header when {@link CGridView::selectableRows} is greater than 1.

	 */

	protected function renderHeaderCellContent()

	{

		if($this->grid->selectableRows>1)

			echo CHtml::checkBox($this->id.'_all',false);

		else

			parent::renderHeaderCellContent();

	}


	/**

	 * Renders the data cell content.

	 * This method renders a checkbox in the data cell.

	 * @param integer the row number (zero-based)

	 * @param mixed the data associated with the row

	 */

	protected function renderDataCellContent($row,$data)

	{

		if($this->value!==null)

			$value=$this->evaluateExpression($this->value,array('data'=>$data,'row'=>$row));

		else if($this->name!==null)

			$value=CHtml::value($data,$this->name);

		else

			$value=$this->grid->dataProvider->keys[$row];

		$options=$this->checkBoxHtmlOptions;

		$options['value']=$value;

		$options['id']=$this->id.'_'.$row;

		//echo CHtml::checkBox($this->id.'[]',false,$options); 

		echo CHtml::checkBox($this->name,false,$options);

//above this changed by me <img src='http://www.yiiframework.com/forum/public/style_emoticons/default/smile.gif' class='bbc_emoticon' alt=':)' />

	}

}



I’ve submited a issue for this

http://code.google.com/p/yii/issues/detail?id=1525 :)

sorry

echo CHtml::checkBox($options[‘name’],false,$options);

would be better.

and //$name="{$this->id}\\[\\]"; should not modify again :)