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的情况下。