Yii Framework v1.1.10 绫诲弬鑰

CGridView

zii.widgets.grid
缁ф壙 class CGridView » CBaseListView » CWidget » CBaseController » CComponent
婧愯嚜 1.1
鐗堟湰 $Id: CGridView.php 3551 2012-02-02 12:45:25Z mdomba $
婧愮爜 framework/zii/widgets/grid/CGridView.php
CGridView displays a list of data items in terms of a table.

Each row of the table represents the data of a single data item, and a column usually represents an attribute of the item (some columns may correspond to complex expression of attributes or static text).

CGridView supports both sorting and pagination of the data items. The sorting and pagination can be done in AJAX mode or normal page request. A benefit of using CGridView is that when the user browser disables JavaScript, the sorting and pagination automatically degenerate to normal page requests and are still functioning as expected.

CGridView should be used together with a data provider, preferrably a CActiveDataProvider.

The minimal code needed to use CGridView is as follows:

$dataProvider=new CActiveDataProvider('Post');

$this->widget('zii.widgets.grid.CGridView', array(
    'dataProvider'=>$dataProvider,
));


The above code first creates a data provider for the Post ActiveRecord class. It then uses CGridView to display every attribute in every Post instance. The displayed table is equiped with sorting and pagination functionality.

In order to selectively display attributes with different formats, we may configure the CGridView::columns property. For example, we may specify only the title and create_time attributes to be displayed, and the create_time should be properly formatted to show as a time. We may also display the attributes of the related objects using the dot-syntax as shown below:

$this->widget('zii.widgets.grid.CGridView', array(
    'dataProvider'=>$dataProvider,
    'columns'=>array(
        'title',          // display the 'title' attribute
        'category.name',  // display the 'name' attribute of the 'category' relation
        'content:html',   // display the 'content' attribute as purified HTML
        array(            // display 'create_time' using an expression
            'name'=>'create_time',
            'value'=>'date("M j, Y", $data->create_time)',
        ),
        array(            // display 'author.username' using an expression
            'name'=>'authorName',
            'value'=>'$data->author->username',
        ),
        array(            // display a column with "view", "update" and "delete" buttons
            'class'=>'CButtonColumn',
        ),
    ),
));


Please refer to columns for more details about how to configure this property.

鍏叡灞炴

闅愯棌缁ф壙灞炴

灞炴绫诲瀷鎻忚堪瀹氫箟鍦
actionPrefix string actions鐨処D鐨勫墠缂銆 褰撳井浠跺湪CController::actions涓0鏄庝簡 鍔ㄤ綔鎻愪緵鑰咃紝鍙互涓哄叾鍔ㄤ綔鐨処D鎸囧畾鍓嶇紑浠ュ尯鍒 浜庡埆鐨勫井浠舵垨鎺у埗鍣ㄣ傚綋寰欢鐢ㄤ簬鎺у埗鍣 鐨勮鍥句腑鏃讹紝蹇呴』閰嶇疆鍚屾牱鐨勫墠缂銆 CWidget
afterAjaxUpdate string a javascript function that will be invoked after a successful AJAX response is received. CGridView
ajaxUpdate mixed the ID of the container whose content may be updated with an AJAX response. CGridView
ajaxUpdateError string a javascript function that will be invoked if an AJAX update error occurs. CGridView
ajaxUrl mixed the URL for the AJAX requests should be sent to. CGridView
ajaxVar string the name of the GET variable that indicates the request is an AJAX request triggered by this widget. CGridView
baseScriptUrl string the base script URL for all grid view resources (eg javascript, CSS file, images). CGridView
beforeAjaxUpdate string a javascript function that will be invoked before an AJAX update occurs. CGridView
blankDisplay string the text to be displayed in an empty grid cell. CGridView
columns array grid column configuration. CGridView
controller CController 杩斿洖姝ゅ井浠舵墍灞炵殑鎺у埗鍣ㄣ CWidget
cssFile string the URL of the CSS file used by this grid view. CGridView
dataProvider IDataProvider 瑙嗗浘闇瑕佹樉绀虹殑鏁版嵁婧愩 CBaseListView
emptyText string dataProvider涓虹┖鏃舵樉绀虹殑鍐呭銆 CBaseListView
enablePagination boolean 鏄惁鍚敤鍒嗛〉銆傛敞鎰忥細褰IDataProvider::pagination鐨勫睘鎬 dataProvider涓篺alse鏃跺垯姝ゅ睘鎬т负false锛屽嵆涓嶅惎鐢ㄥ垎椤点 褰撳惎鐢ㄥ垎椤垫椂锛岄〉鐮佷細鍦ㄨ鍥句腑鏄剧ず銆 榛樿涓簍rue銆 CBaseListView
enableSorting boolean 鏄惁鍚敤鎺掑簭銆傛敞鎰忥細褰IDataProvider::sort鐨勫睘鎬 dataProvider涓篺alse鏃跺垯姝ゅ睘鎬т负false锛屽嵆涓嶅惎鐢ㄦ帓搴忋 褰撳惎鐢ㄦ帓搴忔椂锛岀偣鍑诲垪鍚嶅氨鍙寜璇ュ垪鎺掑簭銆 榛樿涓簍rue銆 CBaseListView
filter CModel the model instance that keeps the user-entered filter data. CGridView
filterCssClass string the CSS class name for the table row element containing all filter input fields. CGridView
filterPosition string whether the filters should be displayed in the grid view. CGridView
formatter CFormatter the formatter instance. CGridView
hasFooter boolean whether the table should render a footer. CGridView
hideHeader boolean whether to hide the header cells of the grid. CGridView
htmlOptions array 閮ㄤ欢鐨凥TML灞炴с CBaseListView
id string 杩斿洖姝ゅ井浠剁殑ID銆傚鏋滈渶瑕佺殑璇濓紝灏嗙敓浜т竴涓柊鐨処D骞跺皢鍏惰繑鍥炪 CWidget
itemsCssClass string 鏄剧ず鍚勬潯鏁版嵁鐨勫鍣ㄧ殑CSS绫汇傞粯璁や负鈥榠tems鈥欍 CBaseListView
loadingCssClass string the CSS class name that will be assigned to the widget container element when the widget is updating its content via AJAX. CGridView
nullDisplay string the text to be displayed in a data cell when a data value is null. CGridView
owner CBaseController 杩斿洖姝ゅ井浠剁殑鎵鏈夎呮垨鍒涘缓鑰呫 CWidget
pager array pager 鐨勯厤缃俊鎭傞粯璁や负array('class'=>'CLinkPager'). CBaseListView
pagerCssClass string 鏄剧ず椤电爜鐨勫鍣ㄧ殑CSS绫汇傞粯璁や负鈥榩ager鈥欍 CBaseListView
rowCssClass array the CSS class names for the table body rows. CGridView
rowCssClassExpression string a PHP expression that is evaluated for every table body row and whose result is used as the CSS class name for the row. CGridView
selectableRows integer the number of table body rows that can be selected. CGridView
selectionChanged string a javascript function that will be invoked after the row selection is changed. CGridView
showTableOnEmpty boolean whether to display the table even when there is no data. CGridView
skin mixed 寰欢浣跨敤鐨勭毊鑲ょ殑鍚嶇О銆傞粯璁や负鈥渄efault鈥濄 濡傛灉姝ゅ睘鎬ц缃负false锛屽井浠跺皢涓嶄細鏈夌毊鑲よ浣跨敤銆 CWidget
summaryCssClass string 鏄剧ず鎽樿鐨勫鍣ㄧ殑CSS绫汇傞粯璁や负鈥榮ummary鈥欍 CBaseListView
summaryText string 鎽樿鍐呭浣跨敤鐨勬ā鏉裤 涓嬮潰鐨勮繖浜涙爣璁板皢浼氳瀵瑰簲鐨勫唴瀹规浛鎹細
  • {start}: 褰撳墠鏄剧ず鐨勮捣濮嬭鏁 (浠1寮濮)
  • {end}: 褰撳墠鏄剧ず鐨勭粨鏉熻鏁 (浠1寮濮)
  • {count}: 鎬昏鏁
  • {page}: 褰撳墠鏄剧ず鐨勯〉鐮侊紝鑷 1.
CBaseListView
tagName string 瑙嗗浘瀹瑰櫒鐨勬爣绛俱傞粯璁や负鈥榙iv鈥欍 CBaseListView
template string 瑙嗗浘甯冨眬鐨勬ā鏉裤 鍙敤鐨勬爣璁版湁锛歿summary}锛寋items}鍜寋pager}銆 瀹冧滑灏嗚鐩稿簲鐨勬憳瑕侊紝鏁版嵁鍒楄〃鍜屽垎椤垫浛鎹€ CBaseListView
updateSelector string the jQuery selector of the HTML elements that may trigger AJAX updates when they are clicked. CGridView
viewPath string 杩斿洖鍖呭惈姝ゅ井浠舵墍闇鐨勮鍥炬枃浠剁殑璺緞銆 CWidget

鍏叡鏂规硶

闅愯棌缁ф壙鏂规硶

鏂规硶鎻忚堪瀹氫箟鍦
__call() 濡傛灉绫讳腑娌℃湁璋冪殑鏂规硶鍚嶏紝鍒欒皟鐢ㄨ繖涓柟娉曘 CComponent
__construct() 鏋勯犲櫒銆 CWidget
__get() 杩斿洖涓涓睘鎬у笺佷竴涓簨浠跺鐞嗙▼搴忓垪琛ㄦ垨涓涓涓哄悕绉般 CComponent
__isset() 妫鏌ヤ竴涓睘鎬ф槸鍚︿负null銆 CComponent
__set() 璁剧疆涓涓粍浠剁殑灞炴у笺 CComponent
__unset() 璁剧疆涓涓粍浠剁殑灞炴т负null銆 CComponent
actions() 杩斿洖姝idget浣跨敤鐨勫姩浣滅殑鍒楄〃銆 CWidget
asa() 杩斿洖杩欎釜鍚嶅瓧鐨勮涓哄璞° CComponent
attachBehavior() 闄勫姞涓涓涓哄埌缁勪欢銆 CComponent
attachBehaviors() 闄勫姞涓涓涓哄垪琛ㄥ埌缁勪欢銆 CComponent
attachEventHandler() 涓轰簨浠堕檮鍔犱竴涓簨浠跺鐞嗙▼搴忋 CComponent
beginCache() Begins fragment caching. CBaseController
beginClip() Begins recording a clip. CBaseController
beginContent() Begins the rendering of content that is to be decorated by the specified view. CBaseController
beginWidget() Creates a widget and executes it. CBaseController
canGetProperty() 纭畾灞炴ф槸鍚﹀彲璇汇 CComponent
canSetProperty() 纭畾灞炴ф槸鍚﹀彲鍐欍 CComponent
createWidget() Creates a widget and initializes it. CBaseController
detachBehavior() 浠庣粍浠朵腑鍒嗙涓涓涓恒 CComponent
detachBehaviors() 浠庣粍浠朵腑鍒嗙鎵鏈夎涓恒 CComponent
detachEventHandler() 鍒嗙涓涓瓨鍦ㄧ殑浜嬩欢澶勭悊绋嬪簭銆 CComponent
disableBehavior() 绂佺敤涓涓檮鍔犺涓恒 CComponent
disableBehaviors() 绂佺敤缁勪欢闄勫姞鐨勬墍鏈夎涓恒 CComponent
enableBehavior() 鍚敤涓涓檮鍔犺涓恒 CComponent
enableBehaviors() 鍚敤缁勪欢闄勫姞鐨勬墍鏈夎涓恒 CComponent
endCache() Ends fragment caching. CBaseController
endClip() Ends recording a clip. CBaseController
endContent() Ends the rendering of content. CBaseController
endWidget() Ends the execution of the named widget. CBaseController
evaluateExpression() 璁$畻涓涓狿HP琛ㄨ揪寮忥紝鎴栨牴鎹粍浠朵笂涓嬫枃鎵ц鍥炶皟銆 CComponent
getController() 杩斿洖姝ゅ井浠舵墍灞炵殑鎺у埗鍣ㄣ CWidget
getEventHandlers() 杩斿洖涓涓簨浠剁殑闄勫姞澶勭悊绋嬪簭鍒楄〃銆 CComponent
getFormatter() 杩斿洖the formatter instance. Defaults to the 'format' application component. CGridView
getHasFooter() 杩斿洖whether the table should render a footer. This is true if any of the columns has a true CGridColumn::hasFooter value. CGridView
getId() 杩斿洖姝ゅ井浠剁殑ID銆傚鏋滈渶瑕佺殑璇濓紝灏嗙敓浜т竴涓柊鐨処D骞跺皢鍏惰繑鍥炪 CWidget
getOwner() 杩斿洖姝ゅ井浠剁殑鎵鏈夎呮垨鍒涘缓鑰呫 CWidget
getViewFile() 鏍规嵁瑙嗗浘鍚嶆煡鎵捐鍥炬枃浠躲 CWidget
getViewPath() 杩斿洖鍖呭惈姝ゅ井浠舵墍闇鐨勮鍥炬枃浠剁殑璺緞銆 CWidget
hasEvent() 纭畾涓涓簨浠舵槸鍚﹀畾涔夈 CComponent
hasEventHandler() 妫鏌ヤ簨浠舵槸鍚︽湁闄勫姞鐨勫鐞嗙▼搴忋 CComponent
hasProperty() 纭畾灞炴ф槸鍚﹁瀹氫箟銆 CComponent
init() Initializes the grid view. CGridView
raiseEvent() 鍙戣捣涓涓簨浠躲 CComponent
registerClientScript() Registers necessary client scripts. CGridView
render() 娓叉煋涓涓鍥俱 CWidget
renderContent() 娓叉煋瑙嗗浘鐨勪富瑕佸唴瀹广 CBaseListView
renderEmptyText() 娓叉煋鏁版嵁涓虹┖鏃舵樉绀虹殑鍐呭銆 CBaseListView
renderFile() Renders a view file. CBaseController
renderFilter() Renders the filter. CGridView
renderInternal() Renders a view file. CBaseController
renderItems() Renders the data items for the grid view. CGridView
renderKeys() 娓叉煋涓涓殣钘忔爣绛炬暟鎹敭鍊笺 CBaseListView
renderPager() 娓叉煋鍒嗛〉銆 CBaseListView
renderSummary() 娓叉煋鎽樿鍐呭銆 CBaseListView
renderTableBody() Renders the table body. CGridView
renderTableFooter() Renders the table footer. CGridView
renderTableHeader() Renders the table header. CGridView
renderTableRow() Renders a table body row. CGridView
run() 娓叉煋瑙嗗浘銆 CBaseListView
setFormatter() 璁剧疆the formatter instance CGridView
setId() 璁剧疆姝ゅ井浠剁殑ID銆 CWidget
widget() Creates a widget and executes it. CBaseController

鍙椾繚鎶ゆ柟娉

闅愯棌缁ф壙鏂规硶

鏂规硶鎻忚堪瀹氫箟鍦
createDataColumn() Creates a CDataColumn based on a shortcut column specification string. CGridView
initColumns() Creates column objects and initializes them. CGridView
renderSection() 娓叉煋鎸囧畾閮ㄥ垎鐨勫唴瀹广 CBaseListView

灞炴ц缁

afterAjaxUpdate 灞炴
public string $afterAjaxUpdate;

a javascript function that will be invoked after a successful AJAX response is received. The function signature is function(id, data) where 'id' refers to the ID of the grid view, 'data' the received ajax response data.

ajaxUpdate 灞炴
public mixed $ajaxUpdate;

the ID of the container whose content may be updated with an AJAX response. Defaults to null, meaning the container for this grid view instance. If it is set false, it means sorting and pagination will be performed in normal page requests instead of AJAX requests. If the sorting and pagination should trigger the update of multiple containers' content in AJAX fashion, these container IDs may be listed here (separated with comma).

ajaxUpdateError 灞炴
public string $ajaxUpdateError;

a javascript function that will be invoked if an AJAX update error occurs.

The function signature is function(xhr, textStatus, errorThrown, errorMessage)

Note: This handler is not called for JSONP requests, because they do not use an XMLHttpRequest.

Example (add in a call to CGridView):
 ...
 'ajaxUpdateError'=>'function(xhr,ts,et,err){ $("#myerrordiv").text(err); }',
 ...

ajaxUrl 灞炴 锛堝彲鐢ㄨ嚜 v1.1.8锛
public mixed $ajaxUrl;

the URL for the AJAX requests should be sent to. CHtml::normalizeUrl() will be called on this property. If not set, the current page URL will be used for AJAX requests.

ajaxVar 灞炴
public string $ajaxVar;

the name of the GET variable that indicates the request is an AJAX request triggered by this widget. Defaults to 'ajax'. This is effective only when ajaxUpdate is not false.

baseScriptUrl 灞炴
public string $baseScriptUrl;

the base script URL for all grid view resources (eg javascript, CSS file, images). Defaults to null, meaning using the integrated grid view resources (which are published as assets).

beforeAjaxUpdate 灞炴
public string $beforeAjaxUpdate;

a javascript function that will be invoked before an AJAX update occurs. The function signature is function(id,options) where 'id' refers to the ID of the grid view, 'options' the AJAX request options (see jQuery.ajax api manual).

blankDisplay 灞炴 锛堝彲鐢ㄨ嚜 v1.1.7锛
public string $blankDisplay;

the text to be displayed in an empty grid cell. This property will NOT be HTML-encoded when rendering. Defaults to an HTML blank. This differs from nullDisplay in that nullDisplay is only used by CDataColumn to render null data values.

columns 灞炴
public array $columns;

grid column configuration. Each array element represents the configuration for one particular grid column which can be either a string or an array.

When a column is specified as a string, it should be in the format of "name:type:header", where "type" and "header" are optional. A CDataColumn instance will be created in this case, whose CDataColumn::name, CDataColumn::type and CDataColumn::header properties will be initialized accordingly.

When a column is specified as an array, it will be used to create a grid column instance, where the 'class' element specifies the column class name (defaults to CDataColumn if absent). Currently, these official column classes are provided: CDataColumn, CLinkColumn, CButtonColumn and CCheckBoxColumn.

cssFile 灞炴
public string $cssFile;

the URL of the CSS file used by this grid view. Defaults to null, meaning using the integrated CSS file. If this is set false, you are responsible to explicitly include the necessary CSS file in your page.

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

the model instance that keeps the user-entered filter data. When this property is set, the grid view will enable column-based filtering. Each data column by default will display a text field at the top that users can fill in to filter the data. Note that in order to show an input field for filtering, a column must have its CDataColumn::name property set or have CDataColumn::filter as the HTML code for the input field. When this property is not set (null) the filtering is disabled.

filterCssClass 灞炴 锛堝彲鐢ㄨ嚜 v1.1.1锛
public string $filterCssClass;

the CSS class name for the table row element containing all filter input fields. Defaults to 'filters'.

鍙傝

filterPosition 灞炴 锛堝彲鐢ㄨ嚜 v1.1.1锛
public string $filterPosition;

whether the filters should be displayed in the grid view. Valid values include:

鍙傝

formatter 灞炴
public CFormatter getFormatter()
public void setFormatter(CFormatter $value)

the formatter instance. Defaults to the 'format' application component.

hasFooter 灞炴 鍙
public boolean getHasFooter()

whether the table should render a footer. This is true if any of the columns has a true CGridColumn::hasFooter value.

hideHeader 灞炴 锛堝彲鐢ㄨ嚜 v1.1.1锛
public boolean $hideHeader;

whether to hide the header cells of the grid. When this is true, header cells will not be rendered, which means the grid cannot be sorted anymore since the sort links are located in the header. Defaults to false.

loadingCssClass 灞炴 锛堝彲鐢ㄨ嚜 v1.1.1锛
public string $loadingCssClass;

the CSS class name that will be assigned to the widget container element when the widget is updating its content via AJAX. Defaults to 'grid-view-loading'.

nullDisplay 灞炴
public string $nullDisplay;

the text to be displayed in a data cell when a data value is null. This property will NOT be HTML-encoded when rendering. Defaults to an HTML blank.

rowCssClass 灞炴
public array $rowCssClass;

the CSS class names for the table body rows. If multiple CSS class names are given, they will be assigned to the rows sequentially and repeatedly. This property is ignored if rowCssClassExpression is set. Defaults to array('odd', 'even').

rowCssClassExpression 灞炴
public string $rowCssClassExpression;

a PHP expression that is evaluated for every table body row and whose result is used as the CSS class name for the row. In this expression, the variable $row stands for the row number (zero-based), $data is the data model associated with the row, and $this is the grid object.

鍙傝

selectableRows 灞炴
public integer $selectableRows;

the number of table body rows that can be selected. If 0, it means rows cannot be selected. If 1, only one row can be selected. If 2 or any other number, it means multiple rows can be selected. A selected row will have a CSS class named 'selected'. You may also call the JavaScript function $.fn.yiiGridView.getSelection(containerID) to retrieve the key values of the selected rows.

selectionChanged 灞炴
public string $selectionChanged;

a javascript function that will be invoked after the row selection is changed. The function signature is function(id) where 'id' refers to the ID of the grid view. In this function, you may use $.fn.yiiGridView.getSelection(id) to get the key values of the currently selected rows.

鍙傝

showTableOnEmpty 灞炴
public boolean $showTableOnEmpty;

whether to display the table even when there is no data. Defaults to true. The emptyText will be displayed to indicate there is no data.

updateSelector 灞炴 锛堝彲鐢ㄨ嚜 v1.1.7锛
public string $updateSelector;

the jQuery selector of the HTML elements that may trigger AJAX updates when they are clicked. If not set, the pagination links and the sorting links will trigger AJAX updates.

鏂规硶璇︾粏

createDataColumn() 鏂规硶
protected CDataColumn createDataColumn(string $text)
$text string the column specification string
{return} CDataColumn the column instance
婧愮爜锛 framework/zii/widgets/grid/CGridView.php#334 (鏄剧ず)
protected function createDataColumn($text)
{
    if(!
preg_match('/^([\w\.]+)(:(\w*))?(:(.*))?$/',$text,$matches))
        throw new 
CException(Yii::t('zii','The column must be specified in the format of "Name:Type:Label", where "Type" and "Label" are optional.'));
    
$column=new CDataColumn($this);
    
$column->name=$matches[1];
    if(isset(
$matches[3]) && $matches[3]!=='')
        
$column->type=$matches[3];
    if(isset(
$matches[5]))
        
$column->header=$matches[5];
    return 
$column;
}

Creates a CDataColumn based on a shortcut column specification string.

getFormatter() 鏂规硶
public CFormatter getFormatter()
{return} CFormatter the formatter instance. Defaults to the 'format' application component.
婧愮爜锛 framework/zii/widgets/grid/CGridView.php#536 (鏄剧ず)
public function getFormatter()
{
    if(
$this->_formatter===null)
        
$this->_formatter=Yii::app()->format;
    return 
$this->_formatter;
}

getHasFooter() 鏂规硶
public boolean getHasFooter()
{return} boolean whether the table should render a footer. This is true if any of the columns has a true CGridColumn::hasFooter value.
婧愮爜锛 framework/zii/widgets/grid/CGridView.php#525 (鏄剧ず)
public function getHasFooter()
{
    foreach(
$this->columns as $column)
        if(
$column->getHasFooter())
            return 
true;
    return 
false;
}

init() 鏂规硶
public void init()
婧愮爜锛 framework/zii/widgets/grid/CGridView.php#267 (鏄剧ず)
public function init()
{
    
parent::init();

    if(!isset(
$this->htmlOptions['class']))
        
$this->htmlOptions['class']='grid-view';

    if(
$this->baseScriptUrl===null)
        
$this->baseScriptUrl=Yii::app()->getAssetManager()->publish(Yii::getPathOfAlias('zii.widgets.assets')).'/gridview';

    if(
$this->cssFile!==false)
    {
        if(
$this->cssFile===null)
            
$this->cssFile=$this->baseScriptUrl.'/styles.css';
        
Yii::app()->getClientScript()->registerCssFile($this->cssFile);
    }

    
$this->initColumns();
}

Initializes the grid view. This method will initialize required property values and instantiate columns objects.

initColumns() 鏂规硶
protected void initColumns()
婧愮爜锛 framework/zii/widgets/grid/CGridView.php#290 (鏄剧ず)
protected function initColumns()
{
    if(
$this->columns===array())
    {
        if(
$this->dataProvider instanceof CActiveDataProvider)
            
$this->columns=$this->dataProvider->model->attributeNames();
        else if(
$this->dataProvider instanceof IDataProvider)
        {
            
// use the keys of the first row of data as the default columns
            
$data=$this->dataProvider->getData();
            if(isset(
$data[0]) && is_array($data[0]))
                
$this->columns=array_keys($data[0]);
        }
    }
    
$id=$this->getId();
    foreach(
$this->columns as $i=>$column)
    {
        if(
is_string($column))
            
$column=$this->createDataColumn($column);
        else
        {
            if(!isset(
$column['class']))
                
$column['class']='CDataColumn';
            
$column=Yii::createComponent($column$this);
        }
        if(!
$column->visible)
        {
            unset(
$this->columns[$i]);
            continue;
        }
        if(
$column->id===null)
            
$column->id=$id.'_c'.$i;
        
$this->columns[$i]=$column;
    }

    foreach(
$this->columns as $column)
        
$column->init();
}

Creates column objects and initializes them.

registerClientScript() 鏂规硶
public void registerClientScript()
婧愮爜锛 framework/zii/widgets/grid/CGridView.php#350 (鏄剧ず)
public function registerClientScript()
{
    
$id=$this->getId();

    if(
$this->ajaxUpdate===false)
        
$ajaxUpdate=false;
    else
        
$ajaxUpdate=array_unique(preg_split('/\s*,\s*/',$this->ajaxUpdate.','.$id,-1,PREG_SPLIT_NO_EMPTY));
    
$options=array(
        
'ajaxUpdate'=>$ajaxUpdate,
        
'ajaxVar'=>$this->ajaxVar,
        
'pagerClass'=>$this->pagerCssClass,
        
'loadingClass'=>$this->loadingCssClass,
        
'filterClass'=>$this->filterCssClass,
        
'tableClass'=>$this->itemsCssClass,
        
'selectableRows'=>$this->selectableRows,
    );
    if(
$this->ajaxUrl!==null)
        
$options['url']=CHtml::normalizeUrl($this->ajaxUrl);
    if(
$this->updateSelector!==null)
        
$options['updateSelector']=$this->updateSelector;
    if(
$this->enablePagination)
        
$options['pageVar']=$this->dataProvider->getPagination()->pageVar;
    if(
$this->beforeAjaxUpdate!==null)
        
$options['beforeAjaxUpdate']=(strpos($this->beforeAjaxUpdate,'js:')!=='js:' '').$this->beforeAjaxUpdate;
    if(
$this->afterAjaxUpdate!==null)
        
$options['afterAjaxUpdate']=(strpos($this->afterAjaxUpdate,'js:')!=='js:' '').$this->afterAjaxUpdate;
    if(
$this->ajaxUpdateError!==null)
        
$options['ajaxUpdateError']=(strpos($this->ajaxUpdateError,'js:')!=='js:' '').$this->ajaxUpdateError;
    if(
$this->selectionChanged!==null)
        
$options['selectionChanged']=(strpos($this->selectionChanged,'js:')!=='js:' '').$this->selectionChanged;

    
$options=CJavaScript::encode($options);
    
$cs=Yii::app()->getClientScript();
    
$cs->registerCoreScript('jquery');
    
$cs->registerCoreScript('bbq');
    
$cs->registerScriptFile($this->baseScriptUrl.'/jquery.yiigridview.js',CClientScript::POS_END);
    
$cs->registerScript(__CLASS__.'#'.$id,"jQuery('#$id').yiiGridView($options);");
}

Registers necessary client scripts.

renderFilter() 鏂规硶 锛堝彲鐢ㄨ嚜 v1.1.1锛
public void renderFilter()
婧愮爜锛 framework/zii/widgets/grid/CGridView.php#444 (鏄剧ず)
public function renderFilter()
{
    if(
$this->filter!==null)
    {
        echo 
"<tr class=\"{$this->filterCssClass}\">\n";
        foreach(
$this->columns as $column)
            
$column->renderFilterCell();
        echo 
"</tr>\n";
    }
}

Renders the filter.

renderItems() 鏂规硶
public void renderItems()
婧愮爜锛 framework/zii/widgets/grid/CGridView.php#393 (鏄剧ず)
public function renderItems()
{
    if(
$this->dataProvider->getItemCount()>|| $this->showTableOnEmpty)
    {
        echo 
"<table class=\"{$this->itemsCssClass}\">\n";
        
$this->renderTableHeader();
        
ob_start();
        
$this->renderTableBody();
        
$body=ob_get_clean();
        
$this->renderTableFooter();
        echo 
$body// TFOOT must appear before TBODY according to the standard.
        
echo "</table>";
    }
    else
        
$this->renderEmptyText();
}

Renders the data items for the grid view.

renderTableBody() 鏂规硶
public void renderTableBody()
婧愮爜锛 framework/zii/widgets/grid/CGridView.php#481 (鏄剧ず)
public function renderTableBody()
{
    
$data=$this->dataProvider->getData();
    
$n=count($data);
    echo 
"<tbody>\n";

    if(
$n>0)
    {
        for(
$row=0;$row<$n;++$row)
            
$this->renderTableRow($row);
    }
    else
    {
        echo 
'<tr><td colspan="'.count($this->columns).'">';
        
$this->renderEmptyText();
        echo 
"</td></tr>\n";
    }
    echo 
"</tbody>\n";
}

Renders the table body.

renderTableFooter() 鏂规硶
public void renderTableFooter()
婧愮爜锛 framework/zii/widgets/grid/CGridView.php#458 (鏄剧ず)
public function renderTableFooter()
{
    
$hasFilter=$this->filter!==null && $this->filterPosition===self::FILTER_POS_FOOTER;
    
$hasFooter=$this->getHasFooter();
    if(
$hasFilter || $hasFooter)
    {
        echo 
"<tfoot>\n";
        if(
$hasFooter)
        {
            echo 
"<tr>\n";
            foreach(
$this->columns as $column)
                
$column->renderFooterCell();
            echo 
"</tr>\n";
        }
        if(
$hasFilter)
            
$this->renderFilter();
        echo 
"</tfoot>\n";
    }
}

Renders the table footer.

renderTableHeader() 鏂规硶
public void renderTableHeader()
婧愮爜锛 framework/zii/widgets/grid/CGridView.php#413 (鏄剧ず)
public function renderTableHeader()
{
    if(!
$this->hideHeader)
    {
        echo 
"<thead>\n";

        if(
$this->filterPosition===self::FILTER_POS_HEADER)
            
$this->renderFilter();

        echo 
"<tr>\n";
        foreach(
$this->columns as $column)
            
$column->renderHeaderCell();
        echo 
"</tr>\n";

        if(
$this->filterPosition===self::FILTER_POS_BODY)
            
$this->renderFilter();

        echo 
"</thead>\n";
    }
    else if(
$this->filter!==null && ($this->filterPosition===self::FILTER_POS_HEADER || $this->filterPosition===self::FILTER_POS_BODY))
    {
        echo 
"<thead>\n";
        
$this->renderFilter();
        echo 
"</thead>\n";
    }
}

Renders the table header.

renderTableRow() 鏂规硶
public void renderTableRow(integer $row)
$row integer the row number (zero-based).
婧愮爜锛 framework/zii/widgets/grid/CGridView.php#505 (鏄剧ず)
public function renderTableRow($row)
{
    if(
$this->rowCssClassExpression!==null)
    {
        
$data=$this->dataProvider->data[$row];
        echo 
'<tr class="'.$this->evaluateExpression($this->rowCssClassExpression,array('row'=>$row,'data'=>$data)).'">';
    }
    else if(
is_array($this->rowCssClass) && ($n=count($this->rowCssClass))>0)
        echo 
'<tr class="'.$this->rowCssClass[$row%$n].'">';
    else
        echo 
'<tr>';
    foreach(
$this->columns as $column)
        
$column->renderDataCell($row);
    echo 
"</tr>\n";
}

Renders a table body row.

setFormatter() 鏂规硶
public void setFormatter(CFormatter $value)
$value CFormatter the formatter instance
婧愮爜锛 framework/zii/widgets/grid/CGridView.php#546 (鏄剧ず)
public function setFormatter($value)
{
    
$this->_formatter=$value;
}

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