CGridView

优质
小牛编辑
134浏览
2023-12-01
所有包 | 属性 | 方法
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.

公共属性

隐藏继承属性

属性类型描述定义在
actionPrefixstringactions的ID的前缀。 当微件在CController::actions中声明了 动作提供者,可以为其动作的ID指定前缀以区别 于别的微件或控制器。当微件用于控制器 的视图中时,必须配置同样的前缀。CWidget
afterAjaxUpdatestringa javascript function that will be invoked after a successful AJAX response is received.CGridView
ajaxUpdatemixedthe ID of the container whose content may be updated with an AJAX response.CGridView
ajaxUpdateErrorstringa javascript function that will be invoked if an AJAX update error occurs.CGridView
ajaxUrlmixedthe URL for the AJAX requests should be sent to.CGridView
ajaxVarstringthe name of the GET variable that indicates the request is an AJAX request triggered by this widget.CGridView
baseScriptUrlstringthe base script URL for all grid view resources (eg javascript, CSS file, images).CGridView
beforeAjaxUpdatestringa javascript function that will be invoked before an AJAX update occurs.CGridView
blankDisplaystringthe text to be displayed in an empty grid cell.CGridView
columnsarraygrid column configuration.CGridView
controllerCController返回此微件所属的控制器。CWidget
cssFilestringthe URL of the CSS file used by this grid view.CGridView
dataProviderIDataProvider视图需要显示的数据源。CBaseListView
emptyTextstring当dataProvider为空时显示的内容。CBaseListView
enablePaginationboolean是否启用分页。注意:当IDataProvider::pagination的属性 dataProvider为false时则此属性为false,即不启用分页。 当启用分页时,页码会在视图中显示。 默认为true。CBaseListView
enableSortingboolean是否启用排序。注意:当IDataProvider::sort的属性 dataProvider为false时则此属性为false,即不启用排序。 当启用排序时,点击列名就可按该列排序。 默认为true。CBaseListView
filterCModelthe model instance that keeps the user-entered filter data.CGridView
filterCssClassstringthe CSS class name for the table row element containing all filter input fields.CGridView
filterPositionstringwhether the filters should be displayed in the grid view.CGridView
formatterCFormatterthe formatter instance.CGridView
hasFooterbooleanwhether the table should render a footer.CGridView
hideHeaderbooleanwhether to hide the header cells of the grid.CGridView
htmlOptionsarray部件的HTML属性。CBaseListView
idstring返回此微件的ID。如果需要的话,将生产一个新的ID并将其返回。CWidget
itemsCssClassstring显示各条数据的容器的CSS类。默认为‘items’。CBaseListView
loadingCssClassstringthe CSS class name that will be assigned to the widget container element when the widget is updating its content via AJAX.CGridView
nullDisplaystringthe text to be displayed in a data cell when a data value is null.CGridView
ownerCBaseController返回此微件的所有者或创建者。CWidget
pagerarraypager 的配置信息。默认为array('class'=>'CLinkPager').CBaseListView
pagerCssClassstring显示页码的容器的CSS类。默认为‘pager’。CBaseListView
rowCssClassarraythe CSS class names for the table body rows.CGridView
rowCssClassExpressionstringa PHP expression that is evaluated for every table body row and whose result is used as the CSS class name for the row.CGridView
selectableRowsintegerthe number of table body rows that can be selected.CGridView
selectionChangedstringa javascript function that will be invoked after the row selection is changed.CGridView
showTableOnEmptybooleanwhether to display the table even when there is no data.CGridView
skinmixed微件使用的皮肤的名称。默认为“default”。 如果此属性设置为false,微件将不会有皮肤被使用。CWidget
summaryCssClassstring显示摘要的容器的CSS类。默认为‘summary’。CBaseListView
summaryTextstring摘要内容使用的模板。 下面的这些标记将会被对应的内容替换:
  • {start}: 当前显示的起始行数 (从1开始)
  • {end}: 当前显示的结束行数 (从1开始)
  • {count}: 总行数
  • {page}: 当前显示的页码,自 1.
CBaseListView
tagNamestring视图容器的标签。默认为‘div’。CBaseListView
templatestring视图布局的模板。 可用的标记有:{summary},{items}和{pager}。 它们将被相应的摘要,数据列表和分页替换。CBaseListView
updateSelectorstringthe jQuery selector of the HTML elements that may trigger AJAX updates when they are clicked.CGridView
viewPathstring返回包含此微件所需的视图文件的路径。CWidget

公共方法

隐藏继承方法

方法描述定义在
__call()如果类中没有调的方法名,则调用这个方法。CComponent
__construct()构造器。CWidget
__get()返回一个属性值、一个事件处理程序列表或一个行为名称。CComponent
__isset()检查一个属性是否为null。CComponent
__set()设置一个组件的属性值。CComponent
__unset()设置一个组件的属性为null。CComponent
actions()返回此widget使用的动作的列表。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()计算一个PHP表达式,或根据组件上下文执行回调。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。如果需要的话,将生产一个新的ID并将其返回。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 instanceCGridView
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)

  • xhr is the XMLHttpRequest object.
  • textStatus is a string describing the type of error that occurred. Possible values (besides null) are "timeout", "error", "notmodified" and "parsererror"
  • errorThrown is an optional exception object, if one occurred.
  • errorMessage is the CGridView default error message derived from xhr and errorThrown. Usefull if you just want to display this error differently. CGridView by default displays this error with an javascript.alert()
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'.

参见

  • filter
filterPosition 属性 (可用自 v1.1.1) public string $filterPosition;

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

  • header: the filters will be displayed on top of each column's header cell.
  • body: the filters will be displayed right below each column's header cell.
  • footer: the filters will be displayed below each column's footer cell.

参见

  • filter
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
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.

参见

  • rowCssClass
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.

参见

  • selectableRows
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)
$textstringthe column specification string
{return}CDataColumnthe column instance
源码: framework/zii/widgets/grid/CGridView.php#334 (显示) protectedfunctioncreateDataColumn($text)
{
if(!preg_match('/^([w.]+)(:(w*))?(:(.*))?$/',$text,$matches))
thrownewCException(Yii::t('zii','Thecolumnmustbespecifiedintheformatof"Name:Type:Label",where"Type"and"Label"areoptional.'));
$column=newCDataColumn($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}CFormatterthe formatter instance. Defaults to the 'format' application component.
源码: framework/zii/widgets/grid/CGridView.php#536 (显示) publicfunctiongetFormatter()
{
if($this->_formatter===null)
$this->_formatter=Yii::app()->format;
return$this->_formatter;
}
getHasFooter() 方法
public boolean getHasFooter()
{return}booleanwhether 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 (显示) publicfunctiongetHasFooter()
{
foreach($this->columnsas$column)
if($column->getHasFooter())
returntrue;
returnfalse;
}
init() 方法
public void init()
源码: framework/zii/widgets/grid/CGridView.php#267 (显示) publicfunctioninit()
{
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 (显示) protectedfunctioninitColumns()
{
if($this->columns===array())
{
if($this->dataProviderinstanceofCActiveDataProvider)
$this->columns=$this->dataProvider->model->attributeNames();
elseif($this->dataProviderinstanceofIDataProvider)
{
//usethekeysofthefirstrowofdataasthedefaultcolumns
$data=$this->dataProvider->getData();
if(isset($data[0])&&is_array($data[0]))
$this->columns=array_keys($data[0]);
}
}
$id=$this->getId();
foreach($this->columnsas$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->columnsas$column)
$column->init();
}

Creates column objects and initializes them.

registerClientScript() 方法
public void registerClientScript()
源码: framework/zii/widgets/grid/CGridView.php#350 (显示) publicfunctionregisterClientScript()
{
$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:')!==0?'js:':'').$this->beforeAjaxUpdate;
if($this->afterAjaxUpdate!==null)
$options['afterAjaxUpdate']=(strpos($this->afterAjaxUpdate,'js:')!==0?'js:':'').$this->afterAjaxUpdate;
if($this->ajaxUpdateError!==null)
$options['ajaxUpdateError']=(strpos($this->ajaxUpdateError,'js:')!==0?'js:':'').$this->ajaxUpdateError;
if($this->selectionChanged!==null)
$options['selectionChanged']=(strpos($this->selectionChanged,'js:')!==0?'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 (显示) publicfunctionrenderFilter()
{
if($this->filter!==null)
{
echo"<trclass="{$this->filterCssClass}">n";
foreach($this->columnsas$column)
$column->renderFilterCell();
echo"</tr>n";
}
}

Renders the filter.

renderItems() 方法
public void renderItems()
源码: framework/zii/widgets/grid/CGridView.php#393 (显示) publicfunctionrenderItems()
{
if($this->dataProvider->getItemCount()>0||$this->showTableOnEmpty)
{
echo"<tableclass="{$this->itemsCssClass}">n";
$this->renderTableHeader();
ob_start();
$this->renderTableBody();
$body=ob_get_clean();
$this->renderTableFooter();
echo$body;//TFOOTmustappearbeforeTBODYaccordingtothestandard.
echo"</table>";
}
else
$this->renderEmptyText();
}

Renders the data items for the grid view.

renderTableBody() 方法
public void renderTableBody()
源码: framework/zii/widgets/grid/CGridView.php#481 (显示) publicfunctionrenderTableBody()
{
$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><tdcolspan="'.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 (显示) publicfunctionrenderTableFooter()
{
$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->columnsas$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 (显示) publicfunctionrenderTableHeader()
{
if(!$this->hideHeader)
{
echo"<thead>n";

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

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

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

echo"</thead>n";
}
elseif($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)
$rowintegerthe row number (zero-based).
源码: framework/zii/widgets/grid/CGridView.php#505 (显示) publicfunctionrenderTableRow($row)
{
if($this->rowCssClassExpression!==null)
{
$data=$this->dataProvider->data[$row];
echo'<trclass="'.$this->evaluateExpression($this->rowCssClassExpression,array('row'=>$row,'data'=>$data)).'">';
}
elseif(is_array($this->rowCssClass)&&($n=count($this->rowCssClass))>0)
echo'<trclass="'.$this->rowCssClass[$row%$n].'">';
else
echo'<tr>';
foreach($this->columnsas$column)
$column->renderDataCell($row);
echo"</tr>n";
}

Renders a table body row.

setFormatter() 方法
public void setFormatter(CFormatter $value)
$valueCFormatterthe formatter instance
源码: framework/zii/widgets/grid/CGridView.php#546 (显示) publicfunctionsetFormatter($value)
{
$this->_formatter=$value;
}