Friday, 15 June 2012

yii - How to use rowdata variables in CCheckBoxColumn -



yii - How to use rowdata variables in CCheckBoxColumn -

i have grid generated cgridview

'id'=>'grid', 'type'=>'striped bordered condensed', 'selectablerows'=>2, 'dataprovider'=>$data, 'template'=>"{items}", 'rowcssclassexpression'=>'(($data["deleted"])?"deleted":"")', 'ajaxupdate'=>true, 'columns'=>array( array( 'class'=>'ccheckboxcolumn', 'checkboxhtmloptions'=>array( 'name'=>'checkbox[id][]', 'class'=>'grid-checkbox', 'data-aaa'=>'$data["aaa"]', 'data-bbb'=>'$data["bbb"]', ), ),

i can access $data variable in rowcssclassexpression. @ same time in 'checkboxhtmloptions' of ccheckboxcolumn $data parsed string:

<input type="checkbox" ... data-aaa="($data["aaa"])" data-bbb="($data["bbb"])">

how can access $data variable?

the framework not back upwards php expressions htmloptions array. expressions supported checked cssclassexpression disabled , value in ccheckboxcolumn see documentation on properties of ccheckboxcolumn here

the info data cell rendered

public function renderdatacell($row) { $data=$this->grid->dataprovider->data[$row]; $options=$this->htmloptions; if($this->cssclassexpression!==null) { $class=$this->evaluateexpression($this->cssclassexpression,array('row'=>$row,'data'=>$data)); if(!empty($class)) { if(isset($options['class'])) $options['class'].=' '.$class; else $options['class']=$class; } } echo chtml::opentag('td',$options); $this->renderdatacellcontent($row,$data); echo '</td>'; }

refer here source. can see cssclassexpression using evaluateexpression function, evaluates $data based expression.

the solution extend ccheckboxcolumn , overwrite function can creating file mycheckboxcolumn in components folder

<?php class mycheckboxcolumn extend ccheckboxcolumn { public $htmloptionsexpression; public function renderdatacell($row) { $data=$this->grid->dataprovider->data[$row]; $options=$this->htmloptions; if($this->cssclassexpression!==null) { $class=$this->evaluateexpression($this->cssclassexpression,array('row'=>$row,'data'=>$data)); if(!empty($class)) { if(isset($options['class'])) $options['class'].=' '.$class; else $options['class']=$class; } } if($this->htmloptionsexpression != null){ foreach ( $this->htmloptionsexpression $attribute => $optionexpression) { $value=$this->evaluateexpression($optionsexpresion,array('row'=>$row,'data'=>$data)); $options[$attribute] = $value; } } echo chtml::opentag('td',$options); $this->renderdatacellcontent($row,$data); echo '</td>'; } }

and utilize in cgridview

'id'=>'grid', 'type'=>'striped bordered condensed', 'selectablerows'=>2, 'dataprovider'=>$data, 'template'=>"{items}", 'rowcssclassexpression'=>'(($data["deleted"])?"deleted":"")', 'ajaxupdate'=>true, 'columns'=>array( array( 'class'=>'mycheckboxcolumn', 'checkboxhtmloptions'=>array( 'name'=>'checkbox[id][]', 'class'=>'grid-checkbox', ), 'htmloptionsexpression'=>array( 'data-aaa'=>'$data["aaa"]', 'data-bbb'=>'$data["bbb"]', ), ), ),

yii cgridview

No comments:

Post a Comment