# BaseListView

> BaseListView is a base class for widgets displaying data from data provider such as ListView and GridView.

[API reference](/docs/api/index.md) › [yii](/docs/api/yii/index.md) › [widgets](/docs/api/yii/widgets/index.md) › BaseListView

| abstract class | `yii\widgets\BaseListView` |
| --- | --- |
| Extends | [`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/widgets/BaseListView.php`](https://github.com/yiisoft/yii2/blob/22.0/framework/widgets/BaseListView.php#L28) |

2 subclasses:

- [`yii\grid\GridView`](/docs/api/yii/grid/gridview/index.md)
- [`ListView`](/docs/api/yii/widgets/listview/index.md)

BaseListView is a base class for widgets displaying data from data provider
such as ListView and GridView.

It provides features like sorting, paging and also filtering the data.

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

## Properties

| Property | Type | Description | Defined by |
| --- | --- | --- | --- |
| <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) |
| <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) |
| [`$dataProvider`](#property-dataProvider) | [`yii\data\DataProviderInterface`](/docs/api/yii/data/dataproviderinterface/index.md) | The data provider for the view. Default: `null`. | `BaseListView` |
| [`$emptyText`](#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`. | `BaseListView` |
| [`$emptyTextOptions`](#property-emptyTextOptions) | `array` | The HTML attributes for the emptyText of the list view. Default: `['class' => 'empty']`. | `BaseListView` |
| <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 list view should be organized. Default: `"{summary}\n{items}\n{pager}"`. | `BaseListView` |
| [`$options`](#property-options) | `array` | The HTML attributes for the container tag of the list view. Default: `[]`. | `BaseListView` |
| [`$pager`](#property-pager) | `array` | The configuration for the pager widget. Default: `[]`. | `BaseListView` |
| [`$showOnEmpty`](#property-showOnEmpty) | `bool` | Whether to show an empty list view if [`$dataProvider`](/docs/api/yii/widgets/baselistview/index.md#property-dataProvider) returns no data. Default: `false`. | `BaseListView` |
| [`$sorter`](#property-sorter) | `array` | The configuration for the sorter widget. Default: `[]`. | `BaseListView` |
| [`$summary`](#property-summary) | `string\|null` | The HTML content to be displayed as the summary of the list view. Default: `null`. | `BaseListView` |
| [`$summaryOptions`](#property-summaryOptions) | `array` | The HTML attributes for the summary of the list view. Default: `['class' => 'summary']`. | `BaseListView` |
| <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 view. | `BaseListView` |
| <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) |
| [`renderEmpty()`](#method-renderEmpty) | Renders the HTML content indicating that the list view has no data. | `BaseListView` |
| <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) |
| [`renderItems()`](#method-renderItems) abstract | Renders the data models. | `BaseListView` |
| [`renderPager()`](#method-renderPager) | Renders the pager. | `BaseListView` |
| [`renderSection()`](#method-renderSection) | Renders a section of the specified name. | `BaseListView` |
| [`renderSorter()`](#method-renderSorter) | Renders the sorter. | `BaseListView` |
| [`renderSummary()`](#method-renderSummary) | Renders the summary text. | `BaseListView` |
| [`run()`](#method-run) | Runs the widget. | `BaseListView` |
| <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) |

## 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) |

## Property details

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

```php
public yii\data\DataProviderInterface $dataProvider = null
```

The data provider for the view.

This property is required.

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

```php
public string|false|null $emptyText = null
```

The HTML content to be displayed when [`$dataProvider`](/docs/api/yii/widgets/baselistview/index.md#property-dataProvider) does not have any data.

When this is set to `false` no extra HTML content will be generated.
The default value is the text "No results found." which will be translated to the current application language.

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

```php
public array $emptyTextOptions = ['class' => 'empty']
```

The HTML attributes for the emptyText of the list view.

The "tag" element specifies the tag name of the emptyText element and defaults to "div".

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

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

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()`](/docs/api/yii/widgets/baselistview/index.md#method-renderSummary).
- `{items}`: the list items. See [`renderItems()`](/docs/api/yii/widgets/baselistview/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 = []
```

The HTML attributes for the container tag of the list view.

The "tag" element specifies the tag name of the container element and defaults to "div".

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

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

The configuration for the pager widget.

By default, [`LinkPager`](/docs/api/yii/widgets/linkpager/index.md) will be
used to render the pager. You can use a different widget class by configuring the "class" element.
Note that the widget must support the `pagination` property which will be populated with the
[pagination](/docs/api/yii/data/basedataprovider/index.md#property-pagination) value of the [`$dataProvider`](/docs/api/yii/widgets/baselistview/index.md#property-dataProvider) and will overwrite this value.

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

```php
public bool $showOnEmpty = false
```

Whether to show an empty list view if [`$dataProvider`](/docs/api/yii/widgets/baselistview/index.md#property-dataProvider) returns no data.

The default value is false which displays an element according to the [`$emptyText`](/docs/api/yii/widgets/baselistview/index.md#property-emptyText)
and [`$emptyTextOptions`](/docs/api/yii/widgets/baselistview/index.md#property-emptyTextOptions) properties.

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

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

The configuration for the sorter widget.

By default, [`LinkSorter`](/docs/api/yii/widgets/linksorter/index.md) will be
used to render the sorter. You can use a different widget class by configuring the "class" element.
Note that the widget must support the `sort` property which will be populated with the
[sort](/docs/api/yii/data/basedataprovider/index.md#property-sort) value of the [`$dataProvider`](/docs/api/yii/widgets/baselistview/index.md#property-dataProvider) and will overwrite this value.

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

```php
public string|null $summary = null
```

The HTML content to be displayed as the summary of the list view.

If you do not want to show the summary, you may set it with an empty string.

The following tokens will be replaced with the corresponding values:

- `{begin}`: the starting row number (1-based) currently being displayed
- `{end}`: the ending row number (1-based) currently being displayed
- `{count}`: the number of rows currently being displayed
- `{totalCount}`: the total number of rows available
- `{page}`: the page number (1-based) current being displayed
- `{pageCount}`: the number of pages available

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

```php
public array $summaryOptions = ['class' => 'summary']
```

The HTML attributes for the summary of the list view.

The "tag" element specifies the tag name of the summary element and defaults to "div".

## Method details

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

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

Initializes the view.

**Returns**

`mixed`

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

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

Renders the HTML content indicating that the list view has no data.

**Returns**

`string`: The rendering result

**See also**

- [`$emptyText`](/docs/api/yii/widgets/baselistview/index.md#property-emptyText)

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

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

Renders the data models.

**Returns**

`string`: The rendering result.

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

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

Renders the pager.

**Returns**

`string`: The rendering result

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

```php
public function renderSection(string $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` | `string` | 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.

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

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

Renders the sorter.

**Returns**

`string`: The rendering result

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

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

Renders the summary text.

**Returns**

`mixed`

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

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

Runs the widget.

**Returns**

`mixed`