Yii Framework v1.1.10 绫诲弬鑰

CCheckBoxColumn

zii.widgets.grid
缁ф壙 class CCheckBoxColumn » CGridColumn » CComponent
婧愯嚜 1.1
鐗堟湰 $Id: CCheckBoxColumn.php 3437 2011-11-07 15:03:58Z mdomba $
婧愮爜 framework/zii/widgets/grid/CCheckBoxColumn.php
CCheckBoxColumn琛ㄧず琛ㄦ牸瑙嗗浘涓垪鐨勫閫夋銆

CCheckBoxColumn鏀寔涓嶉夛紙鍙锛夛紝鍗曢夊拰澶氶夈 璇ユā鍨嬫槸鏍规嵁selectableRows鏉ョ‘瀹氱殑銆傚湪澶氶夋ā寮忎笅锛屾爣棰樺厓浠跺皢鏄剧ず涓涓澶栫殑澶嶉夋锛 鐐瑰嚮閫変腑鎴栬呬笉閫夋暟鎹厓浠朵腑鐨勬墍鏈夊閫夋銆

Additionally selecting a checkbox can select a grid view row (depending on CGridView::selectableRows value) if selectableRows is null (default).

榛樿鎯呭喌涓嬶紝鍦ㄦ暟鎹厓浠跺憟鐜扮殑澶嶉夋锛 灏嗚窡鏁版嵁妯″瀷涓殑鍏抽敭鍊肩浉鍚屻傚彲浠ュ湪name鎴栬 value涓缃垨鑰呬慨鏀广

鍏叡灞炴

闅愯棌缁ф壙灞炴

灞炴绫诲瀷鎻忚堪瀹氫箟鍦
checkBoxHtmlOptions array the HTML options for the checkboxes. CCheckBoxColumn
checked string a PHP expression that will be evaluated for every data cell and whose result will determine if checkbox for each data cell is checked. CCheckBoxColumn
cssClassExpression string 璁$畻PHP琛ㄨ揪寮忎腑姣忎竴涓暟鎹厓浠讹紝 鍏剁粨鏋滀綔涓鸿繖涓暟鎹厓浠剁殑CSS绫诲悕銆傚湪杩欎釜琛ㄨ揪寮忎腑锛 鍙橀噺$row鏄鍙凤紙闆跺熀纭锛夛紱 $data鏄琛岀殑鏁版嵁妯″瀷锛 $this鏄垪鐨勫璞° CGridColumn
footerHtmlOptions array the HTML options for the footer cell tag. CCheckBoxColumn
grid CGridView 鎷ユ湁姝ゅ垪鐨勮〃鏍艰鍥惧璞° CGridColumn
hasFooter boolean 纭畾姝ゅ垪鏄惁鏈夊簳閮ㄥ厓浠躲 杩欏喅瀹氬熀浜庢槸鍚footer宸茶缃 CGridColumn
headerHtmlOptions array the HTML options for the header cell tag. CCheckBoxColumn
htmlOptions array the HTML options for the data cell tags. CCheckBoxColumn
id string the ID of this column. CGridColumn
name string 鏁版嵁妯″瀷鐨勫睘鎬у悕绉般傜浉搴旂殑灞炴у煎皢鍛堢幇鍦ㄦ瘡涓閫夋鐨勫肩殑鏁版嵁鍏冧欢涓 璇锋敞鎰忓亣濡value鎸囧畾锛屾灞炴у皢琚拷鐣ャ CCheckBoxColumn
selectableRows integer the number of rows that can be checked. CCheckBoxColumn
value 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. CCheckBoxColumn
visible boolean 姝ゅ垪鏄惁鍙銆傞粯璁や负true銆 CGridColumn

鍏叡鏂规硶

闅愯棌缁ф壙鏂规硶

鏂规硶鎻忚堪瀹氫箟鍦
__call() 濡傛灉绫讳腑娌℃湁璋冪殑鏂规硶鍚嶏紝鍒欒皟鐢ㄨ繖涓柟娉曘 CComponent
__construct() 鏋勯犳柟娉曘 CGridColumn
__get() 杩斿洖涓涓睘鎬у笺佷竴涓簨浠跺鐞嗙▼搴忓垪琛ㄦ垨涓涓涓哄悕绉般 CComponent
__isset() 妫鏌ヤ竴涓睘鎬ф槸鍚︿负null銆 CComponent
__set() 璁剧疆涓涓粍浠剁殑灞炴у笺 CComponent
__unset() 璁剧疆涓涓粍浠剁殑灞炴т负null銆 CComponent
asa() 杩斿洖杩欎釜鍚嶅瓧鐨勮涓哄璞° CComponent
attachBehavior() 闄勫姞涓涓涓哄埌缁勪欢銆 CComponent
attachBehaviors() 闄勫姞涓涓涓哄垪琛ㄥ埌缁勪欢銆 CComponent
attachEventHandler() 涓轰簨浠堕檮鍔犱竴涓簨浠跺鐞嗙▼搴忋 CComponent
canGetProperty() 纭畾灞炴ф槸鍚﹀彲璇汇 CComponent
canSetProperty() 纭畾灞炴ф槸鍚﹀彲鍐欍 CComponent
detachBehavior() 浠庣粍浠朵腑鍒嗙涓涓涓恒 CComponent
detachBehaviors() 浠庣粍浠朵腑鍒嗙鎵鏈夎涓恒 CComponent
detachEventHandler() 鍒嗙涓涓瓨鍦ㄧ殑浜嬩欢澶勭悊绋嬪簭銆 CComponent
disableBehavior() 绂佺敤涓涓檮鍔犺涓恒 CComponent
disableBehaviors() 绂佺敤缁勪欢闄勫姞鐨勬墍鏈夎涓恒 CComponent
enableBehavior() 鍚敤涓涓檮鍔犺涓恒 CComponent
enableBehaviors() 鍚敤缁勪欢闄勫姞鐨勬墍鏈夎涓恒 CComponent
evaluateExpression() 璁$畻涓涓狿HP琛ㄨ揪寮忥紝鎴栨牴鎹粍浠朵笂涓嬫枃鎵ц鍥炶皟銆 CComponent
getEventHandlers() 杩斿洖涓涓簨浠剁殑闄勫姞澶勭悊绋嬪簭鍒楄〃銆 CComponent
getHasFooter() 杩斿洖纭畾姝ゅ垪鏄惁鏈夊簳閮ㄥ厓浠躲 杩欏喅瀹氬熀浜庢槸鍚footer宸茶缃 CGridColumn
hasEvent() 纭畾涓涓簨浠舵槸鍚﹀畾涔夈 CComponent
hasEventHandler() 妫鏌ヤ簨浠舵槸鍚︽湁闄勫姞鐨勫鐞嗙▼搴忋 CComponent
hasProperty() 纭畾灞炴ф槸鍚﹁瀹氫箟銆 CComponent
init() 鍒濆鍖栧垪銆 CCheckBoxColumn
raiseEvent() 鍙戣捣涓涓簨浠躲 CComponent
renderDataCell() 娓叉煋涓涓暟鎹厓浠躲 CGridColumn
renderFilterCell() 娓叉煋杩囨护鍣ㄥ厓浠躲 CGridColumn
renderFooterCell() 娓叉煋搴曢儴鍏冧欢銆 CGridColumn
renderHeaderCell() 娓叉煋澶撮儴鍏冧欢銆 CGridColumn

鍙椾繚鎶ゆ柟娉

闅愯棌缁ф壙鏂规硶

鏂规硶鎻忚堪瀹氫箟鍦
renderDataCellContent() 鍛堢幇鐨勬暟鎹厓浠剁殑鍐呭銆 CCheckBoxColumn
renderFilterCellContent() Renders the filter cell content. CGridColumn
renderFooterCellContent() Renders the footer cell content. CGridColumn
renderHeaderCellContent() 鍛堢幇鐨勫ご閮ㄥ厓浠剁殑鍐呭銆 CCheckBoxColumn

灞炴ц缁

checkBoxHtmlOptions 灞炴
public array $checkBoxHtmlOptions;

the HTML options for the checkboxes.

checked 灞炴 锛堝彲鐢ㄨ嚜 v1.1.4锛
public string $checked;

a PHP expression that will be evaluated for every data cell and whose result will determine if checkbox for each data cell is checked. In this expression, the variable $row the row number (zero-based); $data the data model for the row; and $this the column object.

footerHtmlOptions 灞炴
public array $footerHtmlOptions;

the HTML options for the footer cell tag.

headerHtmlOptions 灞炴
public array $headerHtmlOptions;

the HTML options for the header cell tag.

htmlOptions 灞炴
public array $htmlOptions;

the HTML options for the data cell tags.

name 灞炴
public string $name;

鏁版嵁妯″瀷鐨勫睘鎬у悕绉般傜浉搴旂殑灞炴у煎皢鍛堢幇鍦ㄦ瘡涓閫夋鐨勫肩殑鏁版嵁鍏冧欢涓 璇锋敞鎰忓亣濡value鎸囧畾锛屾灞炴у皢琚拷鐣ャ

鍙傝

selectableRows 灞炴 锛堝彲鐢ㄨ嚜 v1.1.6锛
public integer $selectableRows;

the number of rows that can be checked. Possible values:

You may also call the JavaScript function $.fn.yiiGridView.getChecked(containerID,columnID) to retrieve the key values of the checked rows.

value 灞炴
public string $value;

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 $row the row number (zero-based); $data the data model for the row; and $this the column object.

鏂规硶璇︾粏

init() 鏂规硶
public void init()
婧愮爜锛 framework/zii/widgets/grid/CCheckBoxColumn.php#91 (鏄剧ず)
public function init()
{
    if(isset(
$this->checkBoxHtmlOptions['name']))
        
$name=$this->checkBoxHtmlOptions['name'];
    else
    {
        
$name=$this->id;
        if(
substr($name,-2)!=='[]')
            
$name.='[]';
        
$this->checkBoxHtmlOptions['name']=$name;
    }
    
$name=strtr($name,array('['=>"\\[",']'=>"\\]"));

    if(
$this->selectableRows===null)
    {
        if(isset(
$this->checkBoxHtmlOptions['class']))
            
$this->checkBoxHtmlOptions['class'].=' select-on-check';
        else
            
$this->checkBoxHtmlOptions['class']='select-on-check';
        return;
    }

    
$cball=$cbcode='';
    if(
$this->selectableRows==0)
    {
        
//.. read only
        
$cbcode="return false;";
    }
    elseif(
$this->selectableRows==1)
    {
        
//.. only one can be checked, uncheck all other
        
$cbcode="$(\"input:not(#\"+this.id+\")[name='$name']\").prop('checked',false);";
    }
    else
    {
        
//.. process check/uncheck all
        
$cball=<<<CBALL
$('#{$this->id}_all').live('click',function() {
var checked=this.checked;
$("input[name='
$name']").each(function() {this.checked=checked;});
});

CBALL;
        
$cbcode="$('#{$this->id}_all').prop('checked', $(\"input[name='$name']\").length==$(\"input[name='$name']:checked\").length);";
    }

    
$js=$cball;
    
$js.=<<<EOD
$("input[name='$name']").live('click', function() {
$cbcode
});
EOD;
    
Yii::app()->getClientScript()->registerScript(__CLASS__.'#'.$this->id,$js);
}

鍒濆鍖栧垪銆 姝ゆ柟娉曟槸娉ㄥ唽瀹㈡埛绔剼鏈閫夋鍒楁墍蹇呴渶鐨勩

renderDataCellContent() 鏂规硶
protected void renderDataCellContent(integer $row, mixed $data)
$row integer 琛屽彿锛堥浂鍩虹锛
$data mixed 姝よ鐩稿叧鐨勬暟鎹
婧愮爜锛 framework/zii/widgets/grid/CCheckBoxColumn.php#167 (鏄剧ず)
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];

    
$checked false;
    if(
$this->checked!==null)
        
$checked=$this->evaluateExpression($this->checked,array('data'=>$data,'row'=>$row));

    
$options=$this->checkBoxHtmlOptions;
    
$name=$options['name'];
    unset(
$options['name']);
    
$options['value']=$value;
    
$options['id']=$this->id.'_'.$row;
    echo 
CHtml::checkBox($name,$checked,$options);
}

鍛堢幇鐨勬暟鎹厓浠剁殑鍐呭銆 杩欑鏂规硶鍛堢幇鍦ㄦ暟鎹厓浠剁殑澶嶉夋涓

renderHeaderCellContent() 鏂规硶
protected void renderHeaderCellContent()
婧愮爜锛 framework/zii/widgets/grid/CCheckBoxColumn.php#151 (鏄剧ず)
protected function renderHeaderCellContent()
{
    if(
$this->selectableRows===null && $this->grid->selectableRows>1)
        echo 
CHtml::checkBox($this->id.'_all',false,array('class'=>'select-on-check-all'));
    else if(
$this->selectableRows>1)
        echo 
CHtml::checkBox($this->id.'_all',false);
    else
        
parent::renderHeaderCellContent();
}

鍛堢幇鐨勫ご閮ㄥ厓浠剁殑鍐呭銆 杩欎釜鏂规硶灏嗕細鍛堢幇鍦ㄥご閮ㄧ殑澶嶉夋褰selectableRows澶т簬1鎴栬呭湪 selectableRows涓虹┖鍜CGridView::selectableRows澶т簬1鐨勬儏鍐典笅銆

Copyright © 2008-2011 by Yii Software LLC
All Rights Reserved.