包 | zii.widgets.grid |
---|---|
继承 | class CDataColumn » CGridColumn » CComponent |
源自 | 1.1 |
版本 | $Id: CDataColumn.php 3448 2011-11-18 10:21:42Z mDOMba $ |
源码 |
Either name or value should be specified. The former specifies a data attribute name, while the latter a PHP expression whose value should be rendered instead.
The property sortable determines whether the grid view can be sorted according to this column. Note that the name should always be set if the column needs to be sortable. The name value will be used by CSort to render a clickable link in the header cell to trigger the sorting.
公共属性
属性 | 类型 | 描述 | 定义在 |
---|---|---|---|
cssClassExpression | string | 计算PHP表达式中每一个数据元件,
其结果作为这个数据元件的CSS类名。在这个表达式中,
变量$row 是行号(零基础); $data 是该行的数据模型;
$this 是列的对象。 |
CGridColumn |
filter | mixed | the HTML code representing a filter input (eg a text field, a dropdown list) that is used for this data column. | CDataColumn |
footer | string | 底部元件文本。请注意,它不会变成HTML编码。 | CGridColumn |
footerHtmlOptions | array | HTML中底部元件标签的选项。 | CGridColumn |
grid | CGridView | 拥有此列的表格视图对象。 | CGridColumn |
hasFooter | boolean | 确定此列是否有底部元件。 这决定基于是否footer已设置。 | CGridColumn |
header | string | 头部元件文本。请注意,它不会变成HTML编码。 | CGridColumn |
headerHtmlOptions | array | HTML中头部元件标签的选项。 | CGridColumn |
htmlOptions | array | HTML中数据元件标签的选项。 | CGridColumn |
id | string | the ID of this column. | CGridColumn |
name | string | the attribute name of the data model. | CDataColumn |
sortable | boolean | whether the column is sortable. | CDataColumn |
type | string | the type of the attribute value. | CDataColumn |
value | string | a PHP expression that will be evaLuated for every data cell and whose result will be rendered as the content of the data cells. | CDataColumn |
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() | 计算一个PHP表达式,或根据组件上下文执行回调。 | CComponent |
getEventHandlers() | 返回一个事件的附加处理程序列表。 | CComponent |
getHasFooter() | 返回确定此列是否有底部元件。 这决定基于是否footer已设置。 | CGridColumn |
hasEvent() | 确定一个事件是否定义。 | CComponent |
hasEventHandler() | 检查事件是否有附加的处理程序。 | CComponent |
hasProperty() | 确定属性是否被定义。 | CComponent |
init() | Initializes the column. | CDataColumn |
raiseEvent() | 发起一个事件。 | CComponent |
renderDataCell() | 渲染一个数据元件。 | CGridColumn |
renderFilterCell() | 渲染过滤器元件。 | CGridColumn |
renderFooterCell() | 渲染底部元件。 | CGridColumn |
renderHeaderCell() | 渲染头部元件。 | CGridColumn |
受保护方法
方法 | 描述 | 定义在 |
---|---|---|
renderDataCellContent() | Renders the data cell content. | CDataColumn |
renderFilterCellContent() | Renders the filter cell content. | CDataColumn |
renderFooterCellContent() | Renders the footer cell content. | CGridColumn |
renderHeaderCellContent() | Renders the header cell content. | CDataColumn |
属性详细
the HTML code representing a filter input (eg a text field, a dropdown list) that is used for this data column. This property is effective only when CGridView::filter is set. If this property is not set, a text field will be generated as the filter input; If this property is an array, a dropdown list will be generated that uses this property value as the list options. If you don't want a filter for this data column, set this value to false.
the attribute name of the data model. Used for column sorting, filtering and to render the corresponding attribute value in each data cell. If value is specified it will be used to rendered the data cell instead of the attribute value.
参见
- value
- sortable
whether the column is sortable. If so, the header cell will contain a link that may trigger the sorting. Defaults to true. Note that if name is not set, or if name is not allowed by CSort, this property will be treated as false.
参见
- name
the type of the attribute value. This determines how the attribute value is formatted for display. Valid values include those recognizable by CGridView::formatter, such as: raw, text, ntext, html, date, time, datetime, boolean, number, email, image, url. For more details, please refer to CFormatter. Defaults to 'text' which means the attribute value will be HTML-encoded.
a PHP expression that will be evaluated for every data cell and whose result will be rendered
as the content of the data cells. 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()
{
parent::init();
if($this->name===null)
$this->sortable=false;
if($this->name===null && $this->value===null)
throw new CException(Yii::t('zii','Either "name" or "value" must be specified for CDataColumn.'));
}
Initializes the column.
protected void renderDataCellContent(integer $row, mixed $data)
| ||
$row | integer | the row number (zero-based) |
$data | 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);
echo $value===null ? $this->grid->nullDisplay : $this->grid->getFormatter()->format($value,$this->type);
}
Renders the data cell content. This method evaluates value or name and renders the result.
protected void renderFilterCellContent()
|
protected function renderFilterCellContent()
{
if(is_string($this->filter))
echo $this->filter;
else if($this->filter!==false && $this->grid->filter!==null && $this->name!==null && strpos($this->name,'.')===false)
{
if(is_array($this->filter))
echo CHtml::activeDropDownList($this->grid->filter, $this->name, $this->filter, array('id'=>false,'prompt'=>''));
else if($this->filter===null)
echo CHtml::activeTextField($this->grid->filter, $this->name, array('id'=>false));
}
else
parent::renderFilterCellContent();
}
Renders the filter cell content. This method will render the filter as is if it is a string. If filter is an array, it is assumed to be a list of options, and a dropdown selector will be rendered. Otherwise if filter is not false, a text field is rendered.
protected void renderHeaderCellContent()
|
protected function renderHeaderCellContent()
{
if($this->grid->enableSorting && $this->sortable && $this->name!==null)
echo $this->grid->dataProvider->getSort()->link($this->name,$this->header);
else if($this->name!==null && $this->header===null)
{
if($this->grid->dataProvider instanceof CActiveDataProvider)
echo CHtml::encode($this->grid->dataProvider->model->getAttributeLabel($this->name));
else
echo CHtml::encode($this->name);
}
else
parent::renderHeaderCellContent();
}
Renders the header cell content. This method will render a link that can trigger the sorting if the column is sortable.