Options
All
  • Public
  • Public/Protected
  • All
Menu

Class ListView

The ListView widget is used to display data from data provider. Each data model is rendered using the view specified.

For more details and usage information on ListView, see the guide article on data widgets.

author

Mahesh S Warrier https://github.com/codespede

Hierarchy

Index

Constructors

Properties

_models: Model[] = []
dataProvider: DataProvider
var

\yii\data\DataProviderInterface the data provider for the view. This property is required.

emptyText: string | false

The HTML content to be displayed when 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."

see

showOnEmpty

see

emptyTextOptions

emptyTextOptions: {} = ...

Type declaration

  • [key: string]: any
enablePjax: boolean = true

Whether to enable Pjax on this widget.

initialization: Promise<void>

A Promise which resolves when this Component has been successfully initialized.

itemOptions: {} | ((model: Model, key: string, index: number, widget: Widget) => {}) = {}

The HTML attributes for the container of the rendering result of each data model. This can be either an array specifying the common HTML attributes for rendering each data item, or a callback that returns an array of the HTML attributes. The anonymous function will be called once for every data model returned by dataProvider. The "tag" element specifies the tag name of the container element and defaults to "div". If "tag" is false, it means no container element will be rendered.

If this property is specified as a callback, it should have the following signature:

function (model, key, index, widget)
see

\yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.

itemView: string | ((model: Model, key: string, index: number, widget: Widget) => string)

The name of the view for rendering each data item, or a callback (e.g. an anonymous function) for rendering each data item. If it specifies a view name, the following variables will be available in the view:

  • model: mixed, the data model
  • key: mixed, the key value associated with the data item
  • index: integer, the zero-based index of the data item in the items array returned by dataProvider.
  • widget: ListView, this widget instance

Note that the view name is resolved into the view file by the current context of the view object.

If this property is specified as a callback, it should have the following signature:

function (model, key, index, widget)
layout: string = '{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()]].
  • {items}: the list items. See [[renderItems()]].
  • {sorter}: the sorter. See [[renderSorter()]].
  • {pager}: the pager. See [[renderPager()]].
options: {} = ...
var

array 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".

see

\yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.

Type declaration

  • [key: string]: any
pager: LinkPager

The configuration for the pager widget. By default, LinkPager will be used to render the pager. You can use a different widget class by configuring the "class" property. Note that the widget must support the pagination property which will be populated with the [[DataProvider.pagination|pagination]] value of the dataProvider and will overwrite this value.

separator: string = '\n'
var

string the HTML code to be displayed between any two consecutive items.

showOnEmpty: boolean = false

Whether to show an empty list view if dataProvider returns no data. The default value is false which displays an element according to the emptyText and emptyTextOptions properties.

sorter: LinkSorter

The configuration for the sorter widget. By default, LinkSorter will be used to render the sorter. You can use a different widget class by configuring the "class" property. Note that the widget must support the sort property which will be populated with the [[DataProvider.sort|sort]] value of the dataProvider and will overwrite this value.

summary: string

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: {} = {}

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".

see

Html.renderTagAttributes for details on how attributes are being rendered.

Type declaration

  • [key: string]: any
viewParams: {} = {}

Additional parameters to be passed to itemView when it is being rendered. This property is used only when itemView is a string representing a view name.

Type declaration

  • [key: string]: any
autoIdPrefix: string = 'w'

The prefix to the automatically generated widget IDs.

see

getId

counter: number = 0

A counter used to generate id for widgets.

internal

Methods

  • getId(autogenerate?: boolean): string
  • init(): Promise<void>
  • registerAssets(): void
  • render(): Promise<string>
  • Renders a widget.

    throws

    InvalidArgumentException if the view file does not exist.

    Returns Promise<string>

    string the rendering result.

  • renderEmpty(): string
  • renderItem(model: Model, key: string, index: number): Promise<string>
  • Renders a single data model.

    Parameters

    • model: Model

      the data model to be rendered

    • key: string

      the key value associated with the data model

    • index: number

      the zero-based index of the data model in the model array returned by dataProvider.

    Returns Promise<string>

    the rendering result

  • renderItems(): Promise<string>
  • renderPager(): Promise<string>
  • renderSection(name: string): Promise<string>
  • Renders a section of the specified name. If the named section is not supported, false will be returned.

    Parameters

    • name: string

      the section name, e.g., {summary}, {items}.

    Returns Promise<string>

    the rendering result of the section, or false if the named section is not supported.

  • renderSorter(): Promise<string>
  • renderSummary(): Promise<string>
  • run(): Promise<string>

Generated using TypeDoc