# GridView

> The GridView widget is used to display data in a grid.

[API reference](/docs/api/index.md) › [yii](/docs/api/yii/index.md) › [grid](/docs/api/yii/grid/index.md) › GridView

| class | `yii\grid\GridView` |
| --- | --- |
| Extends | [`yii\widgets\BaseListView`](/docs/api/yii/widgets/baselistview/index.md) » [`yii\base\Widget`](/docs/api/yii/base/widget/index.md) » [`yii\base\Component`](/docs/api/yii/base/component/index.md) » [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| Implements | [`yii\base\ViewContextInterface`](/docs/api/yii/base/viewcontextinterface/index.md), [`yii\base\Configurable`](/docs/api/yii/base/configurable/index.md) |
| Since | 2.0 |
| Source | [`framework/grid/GridView.php`](https://github.com/yiisoft/yii2/blob/22.0/framework/grid/GridView.php#L49) |

1 subclass:

- [`yii\debug\widgets\GridView`](/docs/extensions/debug/reference/widgets/gridview/index.md)

The GridView widget is used to display data in a grid.

It provides features like [sorting](/docs/api/yii/widgets/baselistview/index.md#property-sorter), [paging](/docs/api/yii/widgets/baselistview/index.md#property-pager) and also [filtering](/docs/api/yii/grid/gridview/index.md#property-filterModel) the data.

A basic usage looks like the following:

```
<?= GridView::widget([
    'dataProvider' => $dataProvider,
    'columns' => [
        'id',
        'name',
        'created_at:datetime',
        // ...
    ],
]) ?>
```

The columns of the grid table are configured in terms of [`Column`](/docs/api/yii/grid/column/index.md) classes,
which are configured via [`$columns`](/docs/api/yii/grid/gridview/index.md#property-columns).

The look and feel of a grid view can be customized using the large amount of properties.

For more details and usage information on GridView, see the [guide article on data widgets](/docs/guide/output-data-widgets/index.md).

## Properties

| Property | Type | Description | Defined by |
| --- | --- | --- | --- |
| [`$afterRow`](#property-afterRow) | [`Closure`](https://www.php.net/manual/en/class.closure.php) | An anonymous function that is called once AFTER rendering each data model. Default: `null`. | `GridView` |
| <span id="property-autoIdPrefix"></span>[`$autoIdPrefix`](/docs/api/yii/base/widget/index.md#property-autoIdPrefix) static | `string` | The prefix to the automatically generated widget IDs. Default: `'w'`. | [`yii\base\Widget`](/docs/api/yii/base/widget/index.md) |
| [`$beforeRow`](#property-beforeRow) | [`Closure`](https://www.php.net/manual/en/class.closure.php) | An anonymous function that is called once BEFORE rendering each data model. Default: `null`. | `GridView` |
| <span id="property-behaviors"></span>[`$behaviors`](/docs/api/yii/base/component/index.md#property-behaviors) read-only | `array<`[`yii\base\Behavior`](/docs/api/yii/base/behavior/index.md)`<static>>` | List of behaviors attached to this component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="property-caption"></span>`$caption` | `string` | The caption of the grid table Default: `null`. | `GridView` |
| <span id="property-captionOptions"></span>`$captionOptions` | `array` | The HTML attributes for the caption element. Default: `[]`. | `GridView` |
| <span id="property-clientScript"></span>`$clientScript` | `array\|`[`yii\web\client\ClientScriptInterface`](/docs/api/yii/web/client/clientscriptinterface/index.md)`\|null` | Client script class to use for client-side validation. Default: `null`. | `GridView` |
| [`$columns`](#property-columns) | `array` | Grid column configuration. Default: `[]`. | `GridView` |
| [`$dataColumnClass`](#property-dataColumnClass) | `string` | The default data column class if the class name is not explicitly specified when configuring a data column. Default: `null`. | `GridView` |
| <span id="property-dataProvider"></span>[`$dataProvider`](/docs/api/yii/widgets/baselistview/index.md#property-dataProvider) | [`yii\data\DataProviderInterface`](/docs/api/yii/data/dataproviderinterface/index.md) | The data provider for the view. Default: `null`. | [`yii\widgets\BaseListView`](/docs/api/yii/widgets/baselistview/index.md) |
| [`$emptyCell`](#property-emptyCell) | `string` | The HTML display when the content of a cell is empty. Default: `'&nbsp;'`. | `GridView` |
| <span id="property-emptyText"></span>[`$emptyText`](/docs/api/yii/widgets/baselistview/index.md#property-emptyText) | `string\|false\|null` | The HTML content to be displayed when [`$dataProvider`](/docs/api/yii/widgets/baselistview/index.md#property-dataProvider) does not have any data. Default: `null`. | [`yii\widgets\BaseListView`](/docs/api/yii/widgets/baselistview/index.md) |
| <span id="property-emptyTextOptions"></span>[`$emptyTextOptions`](/docs/api/yii/widgets/baselistview/index.md#property-emptyTextOptions) | `array` | The HTML attributes for the emptyText of the list view. Default: `['class' => 'empty']`. | [`yii\widgets\BaseListView`](/docs/api/yii/widgets/baselistview/index.md) |
| [`$filterErrorOptions`](#property-filterErrorOptions) | `array` | The options for rendering every filter error message. Default: `['class' => 'field-error']`. | `GridView` |
| [`$filterErrorSummaryOptions`](#property-filterErrorSummaryOptions) | `array` | The options for rendering the filter error summary. Default: `['class' => 'error-summary']`. | `GridView` |
| [`$filterModel`](#property-filterModel) | [`yii\base\Model`](/docs/api/yii/base/model/index.md)`\|null` | The model that keeps the user-entered filter data. Default: `null`. | `GridView` |
| [`$filterOnFocusOut`](#property-filterOnFocusOut) | `bool` | Whatever to apply filters on losing focus. Default: `true`. Available since 2.0.16. | `GridView` |
| [`$filterPosition`](#property-filterPosition) | `string` | Whether the filters should be displayed in the grid view. Default: `self::FILTER_POS_BODY`. | `GridView` |
| <span id="property-filterRowOptions"></span>`$filterRowOptions` | `array` | The HTML attributes for the filter row element. Default: `['class' => 'filters']`. | `GridView` |
| [`$filterSelector`](#property-filterSelector) | `string\|`[`Closure`](https://www.php.net/manual/en/class.closure.php)`(string, string): string` | JQuery selector for selecting filter input fields. Default: `null`. | `GridView` |
| [`$filterUrl`](#property-filterUrl) | `string\|array\|null` | The URL for returning the filtering result. `Url::to()` will be called to normalize the URL. Default: `null`. | `GridView` |
| <span id="property-footerRowOptions"></span>`$footerRowOptions` | `array` | The HTML attributes for the table footer row. Default: `[]`. | `GridView` |
| [`$formatter`](#property-formatter) | `array\|`[`yii\i18n\Formatter`](/docs/api/yii/i18n/formatter/index.md)`\|null` | The formatter used to format model attribute values into displayable texts. Default: `null`. | `GridView` |
| <span id="property-headerRowOptions"></span>`$headerRowOptions` | `array` | The HTML attributes for the table header row. Default: `[]`. | `GridView` |
| <span id="property-id"></span>[`$id`](/docs/api/yii/base/widget/index.md#property-id) | `string` | Id of the widget. | [`yii\base\Widget`](/docs/api/yii/base/widget/index.md) |
| [`$layout`](#property-layout) | `string` | The layout that determines how different sections of the grid view should be organized. Default: `"{summary}\n{items}\n{pager}"`. | `GridView` |
| [`$options`](#property-options) | `array` | The HTML attributes for the container tag of the grid view. Default: `['class' => 'grid-view']`. | `GridView` |
| <span id="property-overrideFilterSelector"></span>`$overrideFilterSelector` | `bool` | If set, [`$filterSelector`](/docs/api/yii/grid/gridview/index.md#property-filterSelector) overrides the default selector of '#$id input, #$id select' (where $id is the filter row ID) rather than being added to it. Default: `false`. | `GridView` |
| <span id="property-pager"></span>[`$pager`](/docs/api/yii/widgets/baselistview/index.md#property-pager) | `array` | The configuration for the pager widget. Default: `[]`. | [`yii\widgets\BaseListView`](/docs/api/yii/widgets/baselistview/index.md) |
| <span id="property-placeFooterAfterBody"></span>`$placeFooterAfterBody` | `bool` | Whether to place footer after body in DOM if $showFooter is true Default: `false`. Available since 2.0.14. | `GridView` |
| [`$rowOptions`](#property-rowOptions) | `array\|`[`Closure`](https://www.php.net/manual/en/class.closure.php) | The HTML attributes for the table body rows. Default: `[]`. | `GridView` |
| <span id="property-showFooter"></span>`$showFooter` | `bool` | Whether to show the footer section of the grid table. Default: `false`. | `GridView` |
| <span id="property-showHeader"></span>`$showHeader` | `bool` | Whether to show the header section of the grid table. Default: `true`. | `GridView` |
| <span id="property-showOnEmpty"></span>`$showOnEmpty` | `bool` | Whether to show the grid view if [`$dataProvider`](/docs/api/yii/widgets/baselistview/index.md#property-dataProvider) returns no data. Default: `true`. | `GridView` |
| <span id="property-sorter"></span>[`$sorter`](/docs/api/yii/widgets/baselistview/index.md#property-sorter) | `array` | The configuration for the sorter widget. Default: `[]`. | [`yii\widgets\BaseListView`](/docs/api/yii/widgets/baselistview/index.md) |
| <span id="property-summary"></span>[`$summary`](/docs/api/yii/widgets/baselistview/index.md#property-summary) | `string\|null` | The HTML content to be displayed as the summary of the list view. Default: `null`. | [`yii\widgets\BaseListView`](/docs/api/yii/widgets/baselistview/index.md) |
| <span id="property-summaryOptions"></span>[`$summaryOptions`](/docs/api/yii/widgets/baselistview/index.md#property-summaryOptions) | `array` | The HTML attributes for the summary of the list view. Default: `['class' => 'summary']`. | [`yii\widgets\BaseListView`](/docs/api/yii/widgets/baselistview/index.md) |
| <span id="property-tableOptions"></span>`$tableOptions` | `array` | The HTML attributes for the grid table element. Default: `[]`. | `GridView` |
| <span id="property-view"></span>[`$view`](/docs/api/yii/base/widget/index.md#property-view) | [`yii\web\View`](/docs/api/yii/web/view/index.md) | The view object that can be used to render views or view files. | [`yii\base\Widget`](/docs/api/yii/base/widget/index.md) |
| <span id="property-viewPath"></span>[`$viewPath`](/docs/api/yii/base/widget/index.md#property-viewPath) read-only | `string` | The directory containing the view files for this widget. | [`yii\base\Widget`](/docs/api/yii/base/widget/index.md) |

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| <span id="method-__construct"></span>[`__construct()`](/docs/api/yii/base/baseobject/index.md#method-__construct) | Constructor. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-__call"></span>[`__call()`](/docs/api/yii/base/component/index.md#method-__call) | Calls the named method which is not a class method. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-__clone"></span>[`__clone()`](/docs/api/yii/base/component/index.md#method-__clone) | This method is called after the object is created by cloning an existing one. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-__get"></span>[`__get()`](/docs/api/yii/base/component/index.md#method-__get) | Returns the value of a component property. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-__isset"></span>[`__isset()`](/docs/api/yii/base/component/index.md#method-__isset) | Checks if a property is set, i.e. defined and not null. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-__set"></span>[`__set()`](/docs/api/yii/base/component/index.md#method-__set) | Sets the value of a component property. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-__unset"></span>[`__unset()`](/docs/api/yii/base/component/index.md#method-__unset) | Sets a component property to be null. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-afterRun"></span>[`afterRun()`](/docs/api/yii/base/widget/index.md#method-afterRun) | This method is invoked right after a widget is executed. | [`yii\base\Widget`](/docs/api/yii/base/widget/index.md) |
| <span id="method-attachBehavior"></span>[`attachBehavior()`](/docs/api/yii/base/component/index.md#method-attachBehavior) | Attaches a behavior to this component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-attachBehaviors"></span>[`attachBehaviors()`](/docs/api/yii/base/component/index.md#method-attachBehaviors) | Attaches a list of behaviors to the component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-beforeRun"></span>[`beforeRun()`](/docs/api/yii/base/widget/index.md#method-beforeRun) | This method is invoked right before the widget is executed. | [`yii\base\Widget`](/docs/api/yii/base/widget/index.md) |
| <span id="method-begin"></span>[`begin()`](/docs/api/yii/base/widget/index.md#method-begin) static | Begins a widget. | [`yii\base\Widget`](/docs/api/yii/base/widget/index.md) |
| <span id="method-behaviors"></span>[`behaviors()`](/docs/api/yii/base/component/index.md#method-behaviors) | Returns a list of behaviors that this component should behave as. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-canGetProperty"></span>[`canGetProperty()`](/docs/api/yii/base/component/index.md#method-canGetProperty) | Returns a value indicating whether a property can be read. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-canSetProperty"></span>[`canSetProperty()`](/docs/api/yii/base/component/index.md#method-canSetProperty) | Returns a value indicating whether a property can be set. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-className"></span>[`className()`](/docs/api/yii/base/baseobject/index.md#method-className) static | Returns the fully qualified name of this class. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-detachBehavior"></span>[`detachBehavior()`](/docs/api/yii/base/component/index.md#method-detachBehavior) | Detaches a behavior from the component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-detachBehaviors"></span>[`detachBehaviors()`](/docs/api/yii/base/component/index.md#method-detachBehaviors) | Detaches all behaviors from the component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-end"></span>[`end()`](/docs/api/yii/base/widget/index.md#method-end) static | Ends a widget. | [`yii\base\Widget`](/docs/api/yii/base/widget/index.md) |
| <span id="method-ensureBehaviors"></span>[`ensureBehaviors()`](/docs/api/yii/base/component/index.md#method-ensureBehaviors) | Makes sure that the behaviors declared in [`behaviors()`](/docs/api/yii/base/component/index.md#method-behaviors) are attached to this component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-getBehavior"></span>[`getBehavior()`](/docs/api/yii/base/component/index.md#method-getBehavior) | Returns the named behavior object. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-getBehaviors"></span>[`getBehaviors()`](/docs/api/yii/base/component/index.md#method-getBehaviors) | Returns all behaviors attached to this component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-getId"></span>[`getId()`](/docs/api/yii/base/widget/index.md#method-getId) | Returns the ID of the widget. | [`yii\base\Widget`](/docs/api/yii/base/widget/index.md) |
| <span id="method-getView"></span>[`getView()`](/docs/api/yii/base/widget/index.md#method-getView) | Returns the view object that can be used to render views or view files. | [`yii\base\Widget`](/docs/api/yii/base/widget/index.md) |
| <span id="method-getViewPath"></span>[`getViewPath()`](/docs/api/yii/base/widget/index.md#method-getViewPath) | Returns the directory containing the view files for this widget. | [`yii\base\Widget`](/docs/api/yii/base/widget/index.md) |
| <span id="method-hasEventHandlers"></span>[`hasEventHandlers()`](/docs/api/yii/base/component/index.md#method-hasEventHandlers) | Returns a value indicating whether there is any handler attached to the named event. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-hasMethod"></span>[`hasMethod()`](/docs/api/yii/base/component/index.md#method-hasMethod) | Returns a value indicating whether a method is defined. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-hasProperty"></span>[`hasProperty()`](/docs/api/yii/base/component/index.md#method-hasProperty) | Returns a value indicating whether a property is defined for this component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| [`init()`](#method-init) | Initializes the grid view. | `GridView` |
| <span id="method-off"></span>[`off()`](/docs/api/yii/base/component/index.md#method-off) | Detaches an existing event handler from this component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-on"></span>[`on()`](/docs/api/yii/base/component/index.md#method-on) | Attaches an event handler to an event. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-render"></span>[`render()`](/docs/api/yii/base/widget/index.md#method-render) | Renders a view. | [`yii\base\Widget`](/docs/api/yii/base/widget/index.md) |
| [`renderCaption()`](#method-renderCaption) | Renders the caption element. | `GridView` |
| [`renderColumnGroup()`](#method-renderColumnGroup) | Renders the column group HTML. | `GridView` |
| <span id="method-renderEmpty"></span>[`renderEmpty()`](/docs/api/yii/widgets/baselistview/index.md#method-renderEmpty) | Renders the HTML content indicating that the list view has no data. | [`yii\widgets\BaseListView`](/docs/api/yii/widgets/baselistview/index.md) |
| [`renderErrors()`](#method-renderErrors) | Renders validator errors of filter model. | `GridView` |
| <span id="method-renderFile"></span>[`renderFile()`](/docs/api/yii/base/widget/index.md#method-renderFile) | Renders a view file. | [`yii\base\Widget`](/docs/api/yii/base/widget/index.md) |
| [`renderFilters()`](#method-renderFilters) | Renders the filter. | `GridView` |
| [`renderItems()`](#method-renderItems) | Renders the data models for the grid view. | `GridView` |
| <span id="method-renderPager"></span>[`renderPager()`](/docs/api/yii/widgets/baselistview/index.md#method-renderPager) | Renders the pager. | [`yii\widgets\BaseListView`](/docs/api/yii/widgets/baselistview/index.md) |
| [`renderSection()`](#method-renderSection) | Renders a section of the specified name. | `GridView` |
| <span id="method-renderSorter"></span>[`renderSorter()`](/docs/api/yii/widgets/baselistview/index.md#method-renderSorter) | Renders the sorter. | [`yii\widgets\BaseListView`](/docs/api/yii/widgets/baselistview/index.md) |
| <span id="method-renderSummary"></span>[`renderSummary()`](/docs/api/yii/widgets/baselistview/index.md#method-renderSummary) | Renders the summary text. | [`yii\widgets\BaseListView`](/docs/api/yii/widgets/baselistview/index.md) |
| [`renderTableBody()`](#method-renderTableBody) | Renders the table body. | `GridView` |
| [`renderTableFooter()`](#method-renderTableFooter) | Renders the table footer. | `GridView` |
| [`renderTableHeader()`](#method-renderTableHeader) | Renders the table header. | `GridView` |
| [`renderTableRow()`](#method-renderTableRow) | Renders a table row with the given data model and key. | `GridView` |
| [`run()`](#method-run) | Runs the widget. | `GridView` |
| <span id="method-setId"></span>[`setId()`](/docs/api/yii/base/widget/index.md#method-setId) | Sets the ID of the widget. | [`yii\base\Widget`](/docs/api/yii/base/widget/index.md) |
| <span id="method-setView"></span>[`setView()`](/docs/api/yii/base/widget/index.md#method-setView) | Sets the view object to be used by this widget. | [`yii\base\Widget`](/docs/api/yii/base/widget/index.md) |
| <span id="method-trigger"></span>[`trigger()`](/docs/api/yii/base/component/index.md#method-trigger) | Triggers an event. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-widget"></span>[`widget()`](/docs/api/yii/base/widget/index.md#method-widget) static | Creates a widget instance and runs it. | [`yii\base\Widget`](/docs/api/yii/base/widget/index.md) |
| [`createDataColumn()`](#method-createDataColumn) protected | Creates a [`DataColumn`](/docs/api/yii/grid/datacolumn/index.md) object based on a string in the format of "attribute:format:label". | `GridView` |
| [`getClientOptions()`](#method-getClientOptions) protected | Returns the options for the grid view JS widget. | `GridView` |
| [`guessColumns()`](#method-guessColumns) protected | This function tries to guess the columns to show from the given data if [`$columns`](/docs/api/yii/grid/gridview/index.md#property-columns) are not explicitly specified. | `GridView` |
| [`initColumns()`](#method-initColumns) protected | Creates column objects and initializes them. | `GridView` |

## Events

| Event | Type | Description | Defined by |
| --- | --- | --- | --- |
| <span id="event-EVENT_INIT"></span>[`EVENT_INIT`](/docs/api/yii/base/widget/index.md#event-EVENT_INIT) | [`yii\base\Event`](/docs/api/yii/base/event/index.md) | An event that is triggered when the widget is initialized via [`init()`](/docs/api/yii/base/widget/index.md#method-init). Event name: `'init'`. Available since 2.0.11. | [`yii\base\Widget`](/docs/api/yii/base/widget/index.md) |
| <span id="event-EVENT_BEFORE_RUN"></span>[`EVENT_BEFORE_RUN`](/docs/api/yii/base/widget/index.md#event-EVENT_BEFORE_RUN) | [`yii\base\WidgetEvent`](/docs/api/yii/base/widgetevent/index.md) | An event raised right before executing a widget. Event name: `'beforeRun'`. Available since 2.0.11. | [`yii\base\Widget`](/docs/api/yii/base/widget/index.md) |
| <span id="event-EVENT_AFTER_RUN"></span>[`EVENT_AFTER_RUN`](/docs/api/yii/base/widget/index.md#event-EVENT_AFTER_RUN) | [`yii\base\WidgetEvent`](/docs/api/yii/base/widgetevent/index.md) | An event raised right after executing a widget. Event name: `'afterRun'`. Available since 2.0.11. | [`yii\base\Widget`](/docs/api/yii/base/widget/index.md) |

## Constants

| Constant | Value | Description | Defined by |
| --- | --- | --- | --- |
| <span id="const-FILTER_POS_HEADER"></span>`FILTER_POS_HEADER` | `'header'` |  | `GridView` |
| <span id="const-FILTER_POS_FOOTER"></span>`FILTER_POS_FOOTER` | `'footer'` |  | `GridView` |
| <span id="const-FILTER_POS_BODY"></span>`FILTER_POS_BODY` | `'body'` |  | `GridView` |

## Property details

### $afterRow <span id="property-afterRow"></span>

```php
public Closure $afterRow = null
```

An anonymous function that is called once AFTER rendering each data model.

It should have the similar signature as [`$rowOptions`](/docs/api/yii/grid/gridview/index.md#property-rowOptions). The return result of the function
will be rendered directly.

### $beforeRow <span id="property-beforeRow"></span>

```php
public Closure $beforeRow = null
```

An anonymous function that is called once BEFORE rendering each data model.

It should have the similar signature as [`$rowOptions`](/docs/api/yii/grid/gridview/index.md#property-rowOptions). The return result of the function
will be rendered directly.

### $columns <span id="property-columns"></span>

```php
public array $columns = []
```

Grid column configuration.

Each array element represents the configuration
for one particular grid column. For example,

```
[
    ['class' => SerialColumn::class],
    [
        'class' => DataColumn::class, // this line is optional
        'attribute' => 'name',
        'format' => 'text',
        'label' => 'Name',
    ],
    ['class' => CheckboxColumn::class],
]
```

If a column is of class [`DataColumn`](/docs/api/yii/grid/datacolumn/index.md), 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 [attribute](/docs/api/yii/grid/datacolumn/index.md#property-attribute), [format](/docs/api/yii/grid/datacolumn/index.md#property-format),
and/or [label](/docs/api/yii/grid/datacolumn/index.md#property-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:

```
[
    'id',
    'amount:currency:Total Amount',
    'created_at:datetime',
]
```

When using a [`$dataProvider`](/docs/api/yii/widgets/baselistview/index.md#property-dataProvider) with active records, you can also display values from related records,
e.g. the `name` attribute of the `author` relation:

```
// shortcut syntax
'author.name',
// full syntax
[
    'attribute' => 'author.name',
    // ...
]
```

### $dataColumnClass <span id="property-dataColumnClass"></span>

```php
public string $dataColumnClass = null
```

The default data column class if the class name is not explicitly specified when configuring a data column.

Defaults to 'yii\grid\DataColumn'.

### $emptyCell <span id="property-emptyCell"></span>

```php
public string $emptyCell = '&nbsp;'
```

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`](/docs/api/yii/grid/datacolumn/index.md) if a data item is `null`. In that case
the [nullDisplay](/docs/api/yii/i18n/formatter/index.md#property-nullDisplay) property of the [`$formatter`](/docs/api/yii/grid/gridview/index.md#property-formatter) will
be used to indicate an empty data value.

### $filterErrorOptions <span id="property-filterErrorOptions"></span>

```php
public array $filterErrorOptions = ['class' => 'field-error']
```

The options for rendering every filter error message.

This is mainly used by [`Html::error()`](/docs/api/yii/helpers/basehtml/index.md#method-error) when rendering an error message next to every filter input field.

### $filterErrorSummaryOptions <span id="property-filterErrorSummaryOptions"></span>

```php
public array $filterErrorSummaryOptions = ['class' => 'error-summary']
```

The options for rendering the filter error summary.

Please refer to [`Html::errorSummary()`](/docs/api/yii/helpers/basehtml/index.md#method-errorSummary) for more details about how to specify the options.

### $filterModel <span id="property-filterModel"></span>

```php
public yii\base\Model|null $filterModel = null
```

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`](/docs/api/yii/grid/datacolumn/index.md#property-attribute)
property set and the attribute should be active in the current scenario of $filterModel or have
[`DataColumn::$filter`](/docs/api/yii/grid/datacolumn/index.md#property-filter) set as the HTML code for the input field.

When this property is not set (null) the filtering feature is disabled.

### $filterOnFocusOut <span id="property-filterOnFocusOut"></span>

```php
public bool $filterOnFocusOut = true
```

Whatever to apply filters on losing focus.

Leaves an ability to manage filters via yiiGridView JS

**Since**

2.0.16

### $filterPosition <span id="property-filterPosition"></span>

```php
public string $filterPosition = self::FILTER_POS_BODY
```

Whether the filters should be displayed in the grid view.

Valid values include:

- [`FILTER_POS_HEADER`](/docs/api/yii/grid/gridview/index.md#const-FILTER_POS_HEADER): the filters will be displayed on top of each column's header cell.
- [`FILTER_POS_BODY`](/docs/api/yii/grid/gridview/index.md#const-FILTER_POS_BODY): the filters will be displayed right below each column's header cell.
- [`FILTER_POS_FOOTER`](/docs/api/yii/grid/gridview/index.md#const-FILTER_POS_FOOTER): the filters will be displayed below each column's footer cell.

### $filterSelector <span id="property-filterSelector"></span>

```php
public string|Closure(string, string): string $filterSelector = null
```

JQuery selector for selecting filter input fields.

If this is a Closure, it gets the widget ID and the filter row ID as parameters and is expected to return the selector.

By default, this selector is added to the default selector '#$id input, #$id select' (where $id is the filter row ID).
If [`$overrideFilterSelector`](/docs/api/yii/grid/gridview/index.md#property-overrideFilterSelector) is set, this selector is used instead of the default selector.

### $filterUrl <span id="property-filterUrl"></span>

```php
public string|array|null $filterUrl = null
```

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.

### $formatter <span id="property-formatter"></span>

```php
public array|yii\i18n\Formatter|null $formatter = null
```

The formatter used to format model attribute values into displayable texts.

This can be either an instance of [`Formatter`](/docs/api/yii/i18n/formatter/index.md) or an configuration array for creating the [`Formatter`](/docs/api/yii/i18n/formatter/index.md)
instance. If this property is not set, the "formatter" application component will be used.

### $layout <span id="property-layout"></span>

```php
public string $layout = "{summary}\n{items}\n{pager}"
```

The layout that determines how different sections of the grid view should be organized.

The following tokens will be replaced with the corresponding section contents:

- `{summary}`: the summary section. See [`renderSummary()`](/docs/api/yii/widgets/baselistview/index.md#method-renderSummary).
- `{errors}`: the filter model error summary. See [`renderErrors()`](/docs/api/yii/grid/gridview/index.md#method-renderErrors).
- `{items}`: the list items. See [`renderItems()`](/docs/api/yii/grid/gridview/index.md#method-renderItems).
- `{sorter}`: the sorter. See [`renderSorter()`](/docs/api/yii/widgets/baselistview/index.md#method-renderSorter).
- `{pager}`: the pager. See [`renderPager()`](/docs/api/yii/widgets/baselistview/index.md#method-renderPager).

### $options <span id="property-options"></span>

```php
public array $options = ['class' => 'grid-view']
```

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 <span id="property-rowOptions"></span>

```php
public array|Closure $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`](/docs/api/yii/widgets/baselistview/index.md#property-dataProvider). It should have the following signature:

```
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`](/docs/api/yii/widgets/baselistview/index.md#property-dataProvider)
- `$grid`: the GridView object

## Method details

### init() <span id="method-init"></span>

```php
public function init(): mixed
```

Initializes the grid view.

This method will initialize required property values and instantiate [`$columns`](/docs/api/yii/grid/gridview/index.md#property-columns) objects.

**Returns**

`mixed`

### renderCaption() <span id="method-renderCaption"></span>

```php
public function renderCaption(): bool|string
```

Renders the caption element.

**Returns**

`bool|string`: The rendered caption element or `false` if no caption element should be rendered.

### renderColumnGroup() <span id="method-renderColumnGroup"></span>

```php
public function renderColumnGroup(): bool|string
```

Renders the column group HTML.

**Returns**

`bool|string`: The column group HTML or `false` if no column group should be rendered.

### renderErrors() <span id="method-renderErrors"></span>

```php
public function renderErrors(): string
```

Renders validator errors of filter model.

**Returns**

`string`: The rendering result.

### renderFilters() <span id="method-renderFilters"></span>

```php
public function renderFilters(): string
```

Renders the filter.

**Returns**

`string`: The rendering result.

### renderItems() <span id="method-renderItems"></span>

```php
public function renderItems(): string
```

Renders the data models for the grid view.

**Returns**

`string`: The HTML code of table

### renderSection() <span id="method-renderSection"></span>

```php
public function renderSection(mixed $name): string|bool
```

Renders a section of the specified name.

If the named section is not supported, false will be returned.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$name` | `mixed` | The section name, e.g., `{summary}`, `{items}`. |

**Returns**

`string|bool`: The rendering result of the section, or false if the named section is not supported.

### renderTableBody() <span id="method-renderTableBody"></span>

```php
public function renderTableBody(): string
```

Renders the table body.

**Returns**

`string`: The rendering result.

### renderTableFooter() <span id="method-renderTableFooter"></span>

```php
public function renderTableFooter(): string
```

Renders the table footer.

**Returns**

`string`: The rendering result.

### renderTableHeader() <span id="method-renderTableHeader"></span>

```php
public function renderTableHeader(): string
```

Renders the table header.

**Returns**

`string`: The rendering result.

### renderTableRow() <span id="method-renderTableRow"></span>

```php
public function renderTableRow(mixed $model, mixed $key, int $index): string
```

Renders a table row with the given data model and key.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$model` | `mixed` | The data model to be rendered |
| `$key` | `mixed` | The key associated with the data model |
| `$index` | `int` | The zero-based index of the data model among the model array returned by [`$dataProvider`](/docs/api/yii/widgets/baselistview/index.md#property-dataProvider). |

**Returns**

`string`: The rendering result

### run() <span id="method-run"></span>

```php
public function run(): mixed
```

Runs the widget.

**Returns**

`mixed`

### createDataColumn() <span id="method-createDataColumn"></span>

```php
protected function createDataColumn(string $text): yii\grid\DataColumn
```

Creates a [`DataColumn`](/docs/api/yii/grid/datacolumn/index.md) object based on a string in the format of "attribute:format:label".

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$text` | `string` | The column specification string |

**Returns**

[`DataColumn`](/docs/api/yii/grid/datacolumn/index.md): The column instance

**Throws**

- [`yii\base\InvalidConfigException`](/docs/api/yii/base/invalidconfigexception/index.md): if the column specification is invalid

### getClientOptions() <span id="method-getClientOptions"></span>

```php
protected function getClientOptions(): array
```

Returns the options for the grid view JS widget.

**Returns**

`array`: The options

### guessColumns() <span id="method-guessColumns"></span>

```php
protected function guessColumns(): mixed
```

This function tries to guess the columns to show from the given data
if [`$columns`](/docs/api/yii/grid/gridview/index.md#property-columns) are not explicitly specified.

**Returns**

`mixed`

### initColumns() <span id="method-initColumns"></span>

```php
protected function initColumns(): mixed
```

Creates column objects and initializes them.

**Returns**

`mixed`