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鏀寔涓嶉夛紙鍙锛夛紝鍗曢夊拰澶氶夈 璇ユā鍨嬫槸鏍规嵁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 |
footer | string | 搴曢儴鍏冧欢鏂囨湰銆傝娉ㄦ剰锛屽畠涓嶄細鍙樻垚HTML缂栫爜銆 | CGridColumn |
footerHtmlOptions | array | the HTML options for the footer cell tag. | CCheckBoxColumn |
grid | CGridView | 鎷ユ湁姝ゅ垪鐨勮〃鏍艰鍥惧璞° | CGridColumn |
hasFooter | boolean | 纭畾姝ゅ垪鏄惁鏈夊簳閮ㄥ厓浠躲 杩欏喅瀹氬熀浜庢槸鍚footer宸茶缃 | CGridColumn |
header | string | 澶撮儴鍏冧欢鏂囨湰銆傝娉ㄦ剰锛屽畠涓嶄細鍙樻垚HTML缂栫爜銆 | 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 |
鍏叡鏂规硶
鍙椾繚鎶ゆ柟娉
鏂规硶 | 鎻忚堪 | 瀹氫箟鍦 |
---|---|---|
renderDataCellContent() | 鍛堢幇鐨勬暟鎹厓浠剁殑鍐呭銆 | CCheckBoxColumn |
renderFilterCellContent() | Renders the filter cell content. | CGridColumn |
renderFooterCellContent() | Renders the footer cell content. | CGridColumn |
renderHeaderCellContent() | 鍛堢幇鐨勫ご閮ㄥ厓浠剁殑鍐呭銆 | CCheckBoxColumn |
灞炴ц缁
the HTML options for the checkboxes.
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.
the HTML options for the footer cell tag.
the HTML options for the header cell tag.
the HTML options for the data cell tags.
鏁版嵁妯″瀷鐨勫睘鎬у悕绉般傜浉搴旂殑灞炴у煎皢鍛堢幇鍦ㄦ瘡涓閫夋鐨勫肩殑鏁版嵁鍏冧欢涓 璇锋敞鎰忓亣濡value鎸囧畾锛屾灞炴у皢琚拷鐣ャ
鍙傝
the number of rows that can be checked. Possible values:
- 0 - the state of the checkbox cannot be changed (read-only mode)
- 1 - only one row can be checked. Checking a checkbox has nothing to do with selecting the row
- 2 or more - multiple checkboxes can be checked. Checking a checkbox has nothing to do with selecting the row
- null - CGridView::selectableRows is used to control how many checkboxes can be checked. Cheking a checkbox will also select the row.
$.fn.yiiGridView.getChecked(containerID,columnID)
to retrieve the key values of the checked rows.
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.
鏂规硶璇︾粏
public void init()
|
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);
}
鍒濆鍖栧垪銆 姝ゆ柟娉曟槸娉ㄥ唽瀹㈡埛绔剼鏈閫夋鍒楁墍蹇呴渶鐨勩
protected void renderDataCellContent(integer $row, mixed $data)
| ||
$row | integer | 琛屽彿锛堥浂鍩虹锛 |
$data | mixed | 姝よ鐩稿叧鐨勬暟鎹 |
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);
}
鍛堢幇鐨勬暟鎹厓浠剁殑鍐呭銆 杩欑鏂规硶鍛堢幇鍦ㄦ暟鎹厓浠剁殑澶嶉夋涓
protected void renderHeaderCellContent()
|
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鐨勬儏鍐典笅銆