PHP 클래스 yii\grid\GridView

It provides features like sorting, paging and also filtering the data.
부터: 2.0
저자: Qiang Xue ([email protected])
상속: extends yii\widgets\BaseListView
파일 보기 프로젝트 열기: yiisoft/yii2 1 사용 예제들

공개 프로퍼티들

프로퍼티 타입 설명
$afterRow an anonymous function that is called once AFTER rendering each data model. It should have the similar signature as [[rowOptions]]. The return result of the function will be rendered directly.
$beforeRow an anonymous function that is called once BEFORE rendering each data model. It should have the similar signature as [[rowOptions]]. The return result of the function will be rendered directly.
$caption the caption of the grid table
$captionOptions the HTML attributes for the caption element.
$columns grid column configuration. Each array element represents the configuration for one particular grid column. For example, php [ ['class' => SerialColumn::className()], [ 'class' => DataColumn::className(), // this line is optional 'attribute' => 'name', 'format' => 'text', 'label' => 'Name', ], ['class' => CheckboxColumn::className()], ] If a column is of class DataColumn, the "class" element can be omitted. As a shortcut format, a string may be used to specify the configuration of a data column which only contains [[DataColumn::attribute|attribute]], [[DataColumn::format|format]], and/or [[DataColumn::label|label]] options: "attribute:format:label". For example, the above "name" column can also be specified as: "name:text:Name". Both "format" and "label" are optional. They will take default values if absent. Using the shortcut format the configuration for columns in simple cases would look like this: php [ 'id', 'amount:currency:Total Amount', 'created_at:datetime', ] When using a [[dataProvider]] with active records, you can also display values from related records, e.g. the name attribute of the author relation: php shortcut syntax 'author.name', full syntax [ 'attribute' => 'author.name', ... ]
$dataColumnClass the default data column class if the class name is not explicitly specified when configuring a data column. Defaults to 'yii\grid\DataColumn'.
$emptyCell the HTML display when the content of a cell is empty. This property is used to render cells that have no defined content, e.g. empty footer or filter cells. Note that this is not used by the DataColumn if a data item is null. In that case the [[\yii\i18n\Formatter::nullDisplay|nullDisplay]] property of the [[formatter]] will be used to indicate an empty data value.
$filterErrorOptions the options for rendering every filter error message. This is mainly used by [[Html::error()]] when rendering an error message next to every filter input field.
$filterErrorSummaryOptions the options for rendering the filter error summary. Please refer to [[Html::errorSummary()]] for more details about how to specify the options.
$filterModel the model 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 [[DataColumn::attribute]] property set and the attribute should be active in the current scenario of $filterModel or have [[DataColumn::filter]] set as the HTML code for the input field. When this property is not set (null) the filtering feature is disabled.
$filterPosition whether the filters should be displayed in the grid view. Valid values include: - [[FILTER_POS_HEADER]]: the filters will be displayed on top of each column's header cell. - [[FILTER_POS_BODY]]: the filters will be displayed right below each column's header cell. - [[FILTER_POS_FOOTER]]: the filters will be displayed below each column's footer cell.
$filterRowOptions the HTML attributes for the filter row element.
$filterSelector additional jQuery selector for selecting filter input fields
$filterUrl the URL for returning the filtering result. [[Url::to()]] will be called to normalize the URL. If not set, the current controller action will be used. When the user makes change to any filter input, the current filtering inputs will be appended as GET parameters to this URL.
$footerRowOptions the HTML attributes for the table footer row.
$formatter the formatter used to format model attribute values into displayable texts. This can be either an instance of [[Formatter]] or an configuration array for creating the [[Formatter]] instance. If this property is not set, the "formatter" application component will be used.
$headerRowOptions the HTML attributes for the table header row.
$layout the layout that determines how different sections of the list view should be organized. The following tokens will be replaced with the corresponding section contents: - {summary}: the summary section. See [[renderSummary()]]. - {errors}: the filter model error summary. See GridView::renderErrors. - {items}: the list items. See GridView::renderItems. - {sorter}: the sorter. See [[renderSorter()]]. - {pager}: the pager. See [[renderPager()]].
$options the HTML attributes for the container tag of the grid view. The "tag" element specifies the tag name of the container element and defaults to "div".
$rowOptions the HTML attributes for the table body rows. This can be either an array specifying the common HTML attributes for all body rows, or an anonymous function that returns an array of the HTML attributes. The anonymous function will be called once for every data model returned by [[dataProvider]]. It should have the following signature: php function ($model, $key, $index, $grid) - $model: the current data model being rendered - $key: the key value associated with the current data model - $index: the zero-based index of the data model in the model array returned by [[dataProvider]] - $grid: the GridView object
$showFooter whether to show the footer section of the grid table.
$showHeader whether to show the header section of the grid table.
$showOnEmpty whether to show the grid view if [[dataProvider]] returns no data.
$tableOptions the HTML attributes for the grid table element.

공개 메소드들

메소드 설명
init ( ) Initializes the grid view.
renderCaption ( ) : boolean | string Renders the caption element.
renderColumnGroup ( ) : boolean | string Renders the column group HTML.
renderErrors ( ) : string Renders validator errors of filter model.
renderFilters ( ) : string Renders the filter.
renderItems ( ) Renders the data models for the grid view.
renderSection ( $name )
renderTableBody ( ) : string Renders the table body.
renderTableFooter ( ) : string Renders the table footer.
renderTableHeader ( ) : string Renders the table header.
renderTableRow ( mixed $model, mixed $key, integer $index ) : string Renders a table row with the given data model and key.
run ( ) Runs the widget.

보호된 메소드들

메소드 설명
createDataColumn ( string $text ) : DataColumn Creates a DataColumn object based on a string in the format of "attribute:format:label".
getClientOptions ( ) : array Returns the options for the grid view JS widget.
guessColumns ( ) This function tries to guess the columns to show from the given data if [[columns]] are not explicitly specified.
initColumns ( ) Creates column objects and initializes them.

메소드 상세

createDataColumn() 보호된 메소드

Creates a DataColumn object based on a string in the format of "attribute:format:label".
protected createDataColumn ( string $text ) : DataColumn
$text string the column specification string
리턴 DataColumn the column instance

getClientOptions() 보호된 메소드

Returns the options for the grid view JS widget.
protected getClientOptions ( ) : array
리턴 array the options

guessColumns() 보호된 메소드

This function tries to guess the columns to show from the given data if [[columns]] are not explicitly specified.
protected guessColumns ( )

init() 공개 메소드

This method will initialize required property values and instantiate [[columns]] objects.
public init ( )

initColumns() 보호된 메소드

Creates column objects and initializes them.
protected initColumns ( )

renderCaption() 공개 메소드

Renders the caption element.
public renderCaption ( ) : boolean | string
리턴 boolean | string the rendered caption element or `false` if no caption element should be rendered.

renderColumnGroup() 공개 메소드

Renders the column group HTML.
public renderColumnGroup ( ) : boolean | string
리턴 boolean | string the column group HTML or `false` if no column group should be rendered.

renderErrors() 공개 메소드

Renders validator errors of filter model.
public renderErrors ( ) : string
리턴 string the rendering result.

renderFilters() 공개 메소드

Renders the filter.
public renderFilters ( ) : string
리턴 string the rendering result.

renderItems() 공개 메소드

Renders the data models for the grid view.
public renderItems ( )

renderSection() 공개 메소드

public renderSection ( $name )

renderTableBody() 공개 메소드

Renders the table body.
public renderTableBody ( ) : string
리턴 string the rendering result.

renderTableFooter() 공개 메소드

Renders the table footer.
public renderTableFooter ( ) : string
리턴 string the rendering result.

renderTableHeader() 공개 메소드

Renders the table header.
public renderTableHeader ( ) : string
리턴 string the rendering result.

renderTableRow() 공개 메소드

Renders a table row with the given data model and key.
public renderTableRow ( mixed $model, mixed $key, integer $index ) : string
$model mixed the data model to be rendered
$key mixed the key associated with the data model
$index integer the zero-based index of the data model among the model array returned by [[dataProvider]].
리턴 string the rendering result

run() 공개 메소드

Runs the widget.
public run ( )

프로퍼티 상세

$afterRow 공개적으로 프로퍼티

an anonymous function that is called once AFTER rendering each data model. It should have the similar signature as [[rowOptions]]. The return result of the function will be rendered directly.
public $afterRow

$beforeRow 공개적으로 프로퍼티

an anonymous function that is called once BEFORE rendering each data model. It should have the similar signature as [[rowOptions]]. The return result of the function will be rendered directly.
public $beforeRow

$caption 공개적으로 프로퍼티

the caption of the grid table
또한 보기: captionOptions
public $caption

$captionOptions 공개적으로 프로퍼티

the HTML attributes for the caption element.
또한 보기: yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.
또한 보기: caption
public $captionOptions

$columns 공개적으로 프로퍼티

grid column configuration. Each array element represents the configuration for one particular grid column. For example, php [ ['class' => SerialColumn::className()], [ 'class' => DataColumn::className(), // this line is optional 'attribute' => 'name', 'format' => 'text', 'label' => 'Name', ], ['class' => CheckboxColumn::className()], ] If a column is of class DataColumn, the "class" element can be omitted. As a shortcut format, a string may be used to specify the configuration of a data column which only contains [[DataColumn::attribute|attribute]], [[DataColumn::format|format]], and/or [[DataColumn::label|label]] options: "attribute:format:label". For example, the above "name" column can also be specified as: "name:text:Name". Both "format" and "label" are optional. They will take default values if absent. Using the shortcut format the configuration for columns in simple cases would look like this: php [ 'id', 'amount:currency:Total Amount', 'created_at:datetime', ] When using a [[dataProvider]] with active records, you can also display values from related records, e.g. the name attribute of the author relation: php shortcut syntax 'author.name', full syntax [ 'attribute' => 'author.name', ... ]
public $columns

$dataColumnClass 공개적으로 프로퍼티

the default data column class if the class name is not explicitly specified when configuring a data column. Defaults to 'yii\grid\DataColumn'.
public $dataColumnClass

$emptyCell 공개적으로 프로퍼티

the HTML display when the content of a cell is empty. This property is used to render cells that have no defined content, e.g. empty footer or filter cells. Note that this is not used by the DataColumn if a data item is null. In that case the [[\yii\i18n\Formatter::nullDisplay|nullDisplay]] property of the [[formatter]] will be used to indicate an empty data value.
public $emptyCell

$filterErrorOptions 공개적으로 프로퍼티

the options for rendering every filter error message. This is mainly used by [[Html::error()]] when rendering an error message next to every filter input field.
public $filterErrorOptions

$filterErrorSummaryOptions 공개적으로 프로퍼티

the options for rendering the filter error summary. Please refer to [[Html::errorSummary()]] for more details about how to specify the options.
또한 보기: renderErrors()
public $filterErrorSummaryOptions

$filterModel 공개적으로 프로퍼티

the model 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 [[DataColumn::attribute]] property set and the attribute should be active in the current scenario of $filterModel or have [[DataColumn::filter]] set as the HTML code for the input field. When this property is not set (null) the filtering feature is disabled.
public $filterModel

$filterPosition 공개적으로 프로퍼티

whether the filters should be displayed in the grid view. Valid values include: - [[FILTER_POS_HEADER]]: the filters will be displayed on top of each column's header cell. - [[FILTER_POS_BODY]]: the filters will be displayed right below each column's header cell. - [[FILTER_POS_FOOTER]]: the filters will be displayed below each column's footer cell.
public $filterPosition

$filterRowOptions 공개적으로 프로퍼티

the HTML attributes for the filter row element.
또한 보기: yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.
public $filterRowOptions

$filterSelector 공개적으로 프로퍼티

additional jQuery selector for selecting filter input fields
public $filterSelector

$filterUrl 공개적으로 프로퍼티

the URL for returning the filtering result. [[Url::to()]] will be called to normalize the URL. If not set, the current controller action will be used. When the user makes change to any filter input, the current filtering inputs will be appended as GET parameters to this URL.
public $filterUrl

$footerRowOptions 공개적으로 프로퍼티

the HTML attributes for the table footer row.
또한 보기: yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.
public $footerRowOptions

$formatter 공개적으로 프로퍼티

the formatter used to format model attribute values into displayable texts. This can be either an instance of [[Formatter]] or an configuration array for creating the [[Formatter]] instance. If this property is not set, the "formatter" application component will be used.
public $formatter

$headerRowOptions 공개적으로 프로퍼티

the HTML attributes for the table header row.
또한 보기: yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.
public $headerRowOptions

$layout 공개적으로 프로퍼티

the layout that determines how different sections of the list view should be organized. The following tokens will be replaced with the corresponding section contents: - {summary}: the summary section. See [[renderSummary()]]. - {errors}: the filter model error summary. See GridView::renderErrors. - {items}: the list items. See GridView::renderItems. - {sorter}: the sorter. See [[renderSorter()]]. - {pager}: the pager. See [[renderPager()]].
public $layout

$options 공개적으로 프로퍼티

the HTML attributes for the container tag of the grid view. The "tag" element specifies the tag name of the container element and defaults to "div".
또한 보기: yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.
public $options

$rowOptions 공개적으로 프로퍼티

the HTML attributes for the table body rows. This can be either an array specifying the common HTML attributes for all body rows, or an anonymous function that returns an array of the HTML attributes. The anonymous function will be called once for every data model returned by [[dataProvider]]. It should have the following signature: php function ($model, $key, $index, $grid) - $model: the current data model being rendered - $key: the key value associated with the current data model - $index: the zero-based index of the data model in the model array returned by [[dataProvider]] - $grid: the GridView object
또한 보기: yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.
public $rowOptions

$showFooter 공개적으로 프로퍼티

whether to show the footer section of the grid table.
public $showFooter

$showHeader 공개적으로 프로퍼티

whether to show the header section of the grid table.
public $showHeader

$showOnEmpty 공개적으로 프로퍼티

whether to show the grid view if [[dataProvider]] returns no data.
public $showOnEmpty

$tableOptions 공개적으로 프로퍼티

the HTML attributes for the grid table element.
또한 보기: yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.
public $tableOptions