Yii Framework v1.1.10 绫诲弬鑰

CDataColumn

zii.widgets.grid
缁ф壙 class CDataColumn » CGridColumn » CComponent
婧愯嚜 1.1
鐗堟湰 $Id: CDataColumn.php 3448 2011-11-18 10:21:42Z mdomba $
婧愮爜 framework/zii/widgets/grid/CDataColumn.php
CDataColumn浠h〃缃戞牸瑙嗗浘鐨勫垪鐨勬暟鎹睘鎬ф垨琛ㄨ揪鐩稿叧鑱斻

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
footerHtmlOptions array HTML涓簳閮ㄥ厓浠舵爣绛剧殑閫夐」銆 CGridColumn
grid CGridView 鎷ユ湁姝ゅ垪鐨勮〃鏍艰鍥惧璞° CGridColumn
hasFooter boolean 纭畾姝ゅ垪鏄惁鏈夊簳閮ㄥ厓浠躲 杩欏喅瀹氬熀浜庢槸鍚footer宸茶缃 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() 璁$畻涓涓狿HP琛ㄨ揪寮忥紝鎴栨牴鎹粍浠朵笂涓嬫枃鎵ц鍥炶皟銆 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

灞炴ц缁

filter 灞炴 锛堝彲鐢ㄨ嚜 v1.1.1锛
public mixed $filter;

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.

name 灞炴
public string $name;

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.

鍙傝

sortable 灞炴
public boolean $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.

鍙傝

type 灞炴
public string $type;

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.

value 灞炴
public string $value;

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.

鏂规硶璇︾粏

init() 鏂规硶
public void init()
婧愮爜锛 framework/zii/widgets/grid/CDataColumn.php#80 (鏄剧ず)
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.

renderDataCellContent() 鏂规硶
protected void renderDataCellContent(integer $row, mixed $data)
$row integer the row number (zero-based)
$data mixed the data associated with the row
婧愮爜锛 framework/zii/widgets/grid/CDataColumn.php#136 (鏄剧ず)
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.

renderFilterCellContent() 鏂规硶 锛堝彲鐢ㄨ嚜 v1.1.1锛
protected void renderFilterCellContent()
婧愮爜锛 framework/zii/widgets/grid/CDataColumn.php#96 (鏄剧ず)
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.

renderHeaderCellContent() 鏂规硶
protected void renderHeaderCellContent()
婧愮爜锛 framework/zii/widgets/grid/CDataColumn.php#115 (鏄剧ず)
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.

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