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
Показать файл Открыть проект Примеры использования класса

Открытые свойства

Свойство Тип Описание
$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