Final Class Yiisoft\Yii\DataView\GridView\GridView
| Inheritance | Yiisoft\Yii\DataView\GridView\GridView » Yiisoft\Yii\DataView\BaseListView » Yiisoft\Widget\Widget |
|---|
The GridView widget displays data in a grid.
You can configure the columns of the grid table in terms of {@see \Yiisoft\Yii\DataView\GridView\Column} classes configured via {@see \Yiisoft\Yii\DataView\GridView\columns}.
The look and feel of a grid view can be customized using many properties.
Protected Properties
| Property | Type | Description | Defined By |
|---|---|---|---|
| $multiSort | boolean | Yiisoft\Yii\DataView\BaseListView | |
| $translationCategory | string | Yiisoft\Yii\DataView\BaseListView | |
| $translator | \Yiisoft\Translator\TranslatorInterface | A translator instance used for translations of messages. | Yiisoft\Yii\DataView\BaseListView |
| $urlConfig | Yiisoft\Yii\DataView\Url\UrlConfig | Yiisoft\Yii\DataView\BaseListView | |
| $urlCreator | Yiisoft\Yii\DataView\BaseListView | ||
| $urlParameterProvider | Yiisoft\Yii\DataView\Url\UrlParameterProviderInterface | Yiisoft\Yii\DataView\BaseListView |
Public Methods
Protected Methods
Constants
| Constant | Value | Description | Defined By |
|---|---|---|---|
| DEFAULT_TRANSLATION_CATEGORY | 'yii-dataview' | A name for {@see CategorySource} used with translator ({@see TranslatorInterface}) by default. | Yiisoft\Yii\DataView\BaseListView |
Method Details
| public mixed __construct ( \Psr\Container\ContainerInterface $columnRenderersDependencyContainer, \Yiisoft\Translator\TranslatorInterface|null $translator = null ) | ||
| $columnRenderersDependencyContainer | \Psr\Container\ContainerInterface |
Container used to resolve {@see \Yiisoft\Yii\DataView\GridView\Column\ColumnRendererInterface column renderer} dependencies. |
| $translator | \Yiisoft\Translator\TranslatorInterface|null |
Translator instance or |
public function __construct(
ContainerInterface $columnRenderersDependencyContainer,
?TranslatorInterface $translator = null,
) {
$this->filterFormId = Html::generateId();
$this->columnRendererContainer = new RendererContainer($columnRenderersDependencyContainer);
parent::__construct($translator);
}
Add configurations for a column renderers.
| public self addColumnRendererConfigs ( array $configs ) | ||
| $configs | array | |
| return | self |
New instance with the added column renderer configurations. |
|---|---|---|
public function addColumnRendererConfigs(array $configs): self
{
$new = clone $this;
$new->columnRendererContainer = $this->columnRendererContainer->addConfigs($configs);
return $new;
}
Defined in: Yiisoft\Yii\DataView\BaseListView::addContainerClass()
Adds one or more CSS classes to the existing container classes.
Multiple classes can be added by passing them as separate arguments. null values are filtered out
automatically.
| public static addContainerClass ( \BackedEnum|string|null $class ) | ||
| $class | \BackedEnum|string|null |
One or more CSS class names to add. Pass |
| return | Yiisoft\Yii\DataView\BaseListView |
A new instance with the specified CSS classes added to existing ones. |
|---|---|---|
public function addContainerClass(BackedEnum|string|null ...$class): static
{
$new = clone $this;
Html::addCssClass($new->containerAttributes, $class);
return $new;
}
| public static addHeaderClass ( \BackedEnum|string|null $class ) | ||
| $class | \BackedEnum|string|null | |
public function addHeaderClass(BackedEnum|string|null ...$class): static
{
$new = clone $this;
Html::addCssClass($new->headerAttributes, $class);
return $new;
}
Add one or more CSS classes to the table tag.
| public self addTableClass ( string|null $class ) | ||
| $class | string|null |
One or many CSS classes. |
| return | self |
New instance with the added table CSS classes. |
|---|---|---|
public function addTableClass(?string ...$class): self
{
$new = clone $this;
Html::addCssClass($new->tableAttributes, $class);
return $new;
}
Add one or more CSS classes to the tbody tag.
| public self addTbodyClass ( string|null $class ) | ||
| $class | string|null |
One or many CSS classes. |
| return | self |
New instance with the added tbody CSS classes. |
|---|---|---|
public function addTbodyClass(?string ...$class): self
{
$new = clone $this;
Html::addCssClass($new->tbodyAttributes, $class);
return $new;
}
Returns a new instance with a callback that is executed once AFTER rendering each data row.
| public self afterRow ( Closure|null $callback ) | ||
| $callback | Closure|null |
The callback with the following signature:
The callback should return either:
|
| return | self |
New instance with the after row callback. |
|---|---|---|
public function afterRow(?Closure $callback): self
{
$new = clone $this;
$new->afterRowCallback = $callback;
return $new;
}
Defined in: Yiisoft\Yii\DataView\BaseListView::append()
Returns a new instance with HTML content to be added before the closing container tag.
| public static append ( string|\Stringable $append ) | ||
| $append | string|\Stringable |
The HTML content to be appended. |
final public function append(string|Stringable ...$append): static
{
$new = clone $this;
$new->append = implode('', $append);
return $new;
}
Return a new instance with a callback that is executed BEFORE rendering each data row.
| public self beforeRow ( Closure|null $callback ) | ||
| $callback | Closure|null |
The callback with the following signature:
The callback should return either:
|
| return | self |
New instance with the before row callback. |
|---|---|---|
public function beforeRow(?Closure $callback): self
{
$new = clone $this;
$new->beforeRowCallback = $callback;
return $new;
}
Return new instance with the HTML attributes for the td tag.
| public self bodyCellAttributes ( array $attributes ) | ||
| $attributes | array |
The tag attributes in terms of name-value pairs. |
| return | self |
New instance with the body cell attributes. |
|---|---|---|
public function bodyCellAttributes(array $attributes): self
{
$new = clone $this;
$new->bodyCellAttributes = $attributes;
return $new;
}
Return new instance with the HTML attributes for body rows of the grid.
| public self bodyRowAttributes ( array|Closure $attributes ) | ||
| $attributes | array|Closure |
Attribute values indexed by attribute names or a callable that returns them. The signature of the callable should be:
If an array passed, the attribute values also can be a callable that returns them. The signature of the callable should be:
|
| return | self |
New instance with the body row attributes. |
|---|---|---|
public function bodyRowAttributes(Closure|array $attributes): self
{
$new = clone $this;
$new->bodyRowAttributes = $attributes;
return $new;
}
Return new instance with the content for the caption tag.
| public self caption ( string|\Stringable|null $content ) | ||
| $content | string|\Stringable|null |
Caption content. Set to |
| return | self |
New instance with the caption content. |
|---|---|---|
public function caption(string|Stringable|null $content): self
{
$new = clone $this;
$new->caption = $content;
return $new;
}
Returns a new instance with the column grouping enabled.
See also:
| public self columnGrouping ( boolean $enabled = true ) | ||
| $enabled | boolean |
Whether to enable the column grouping. |
| return | self |
New instance with the column grouping enabled. |
|---|---|---|
public function columnGrouping(bool $enabled = true): self
{
$new = clone $this;
$new->columnGrouping = $enabled;
return $new;
}
Return new instance with the specified column configurations.
| public self columns ( Yiisoft\Yii\DataView\GridView\Column\ColumnInterface $columns ) | ||
| $columns | Yiisoft\Yii\DataView\GridView\Column\ColumnInterface |
The grid column configuration. Each element represents the configuration for one particular grid column. For example,
|
| return | self |
New instance with the column configurations. |
|---|---|---|
public function columns(ColumnInterface ...$columns): self
{
$new = clone $this;
$new->columns = $columns;
return $new;
}
Defined in: Yiisoft\Yii\DataView\BaseListView::containerAttributes()
Returns a new instance with the HTML attributes for container.
| public static containerAttributes ( array $attributes ) | ||
| $attributes | array |
Attribute values indexed by attribute names. |
final public function containerAttributes(array $attributes): static
{
$new = clone $this;
$new->containerAttributes = $attributes;
return $new;
}
Defined in: Yiisoft\Yii\DataView\BaseListView::containerClass()
Set new container classes.
Multiple classes can be set by passing them as separate arguments. null values are filtered out
automatically.
| public static containerClass ( \BackedEnum|string|null $class ) | ||
| $class | \BackedEnum|string|null |
One or more CSS class names to use. Pass |
| return | Yiisoft\Yii\DataView\BaseListView |
A new instance with the specified CSS classes set. |
|---|---|---|
public function containerClass(BackedEnum|string|null ...$class): static
{
$new = clone $this;
$new->containerAttributes['class'] = [];
Html::addCssClass($new->containerAttributes, $class);
return $new;
}
| public static containerTag ( ?string $tag ) | ||
| $tag | ?string | |
final public function containerTag(?string $tag): static
{
if ($tag === '') {
throw new InvalidArgumentException('Tag name cannot be empty.');
}
$new = clone $this;
$new->containerTag = $tag;
return $new;
}
Defined in: Yiisoft\Yii\DataView\BaseListView::dataReader()
| public static dataReader ( \Yiisoft\Data\Reader\ReadableDataInterface $dataReader ) | ||
| $dataReader | \Yiisoft\Data\Reader\ReadableDataInterface | |
final public function dataReader(ReadableDataInterface $dataReader): static
{
$new = clone $this;
$new->dataReader = $dataReader;
return $new;
}
Return new instance with the HTML to display when the content is empty.
| public self emptyCell ( string $content, array|null $attributes = null ) | ||
| $content | string |
HTML content. Defaults to |
| $attributes | array|null |
The HTML attributes for the empty cell. Attribute values indexed by attribute names. |
| return | self |
New instance with the empty cell content. |
|---|---|---|
public function emptyCell(string $content, ?array $attributes = null): self
{
$new = clone $this;
$new->emptyCell = $content;
if ($attributes !== null) {
$new->emptyCellAttributes = $attributes;
}
return $new;
}
Returns a new instance with the HTML attributes for the empty cell.
| public self emptyCellAttributes ( array $attributes ) | ||
| $attributes | array |
The HTML attributes for the empty cell. Attribute values indexed by attribute names. |
| return | self |
New instance with the empty cell attributes. |
|---|---|---|
public function emptyCellAttributes(array $attributes): self
{
$new = clone $this;
$new->emptyCellAttributes = $attributes;
return $new;
}
Return new instance whether to show the header section of the grid.
| public self enableHeader ( boolean $enabled = true ) | ||
| $enabled | boolean |
Whether to show the header section of the grid. |
| return | self |
New instance with the header section visibility setting. |
|---|---|---|
public function enableHeader(bool $enabled = true): self
{
$new = clone $this;
$new->isHeaderEnabled = $enabled;
return $new;
}
| public static encodeHeader ( boolean $encode ) | ||
| $encode | boolean | |
final public function encodeHeader(bool $encode): static
{
$new = clone $this;
$new->encodeHeader = $encode;
return $new;
}
Return new instance with the HTML attributes for the filter cell (td) tag.
| public self filterCellAttributes ( array $attributes ) | ||
| $attributes | array |
Attribute values indexed by attribute names. |
| return | self |
New instance with the filter cell attributes. |
|---|---|---|
public function filterCellAttributes(array $attributes): self
{
$new = clone $this;
$new->filterCellAttributes = $attributes;
return $new;
}
Return new instance with the CSS class to be added to filter cells that contain invalid values.
| public self filterCellInvalidClass ( string|null $class ) | ||
| $class | string|null |
The CSS class name. Set to null to remove the class. |
| return | self |
New instance with the filter cell invalid class. |
|---|---|---|
public function filterCellInvalidClass(?string $class): self
{
$new = clone $this;
$new->filterCellInvalidClass = $class;
return $new;
}
Return new instance with the HTML attributes for the filter errors container.
This container will be rendered below the filter cell when validation fails.
| public self filterErrorsContainerAttributes ( array $attributes ) | ||
| $attributes | array |
Attribute values indexed by attribute names. |
| return | self |
New instance with the filter errors container attributes. |
|---|---|---|
public function filterErrorsContainerAttributes(array $attributes): self
{
$new = clone $this;
$new->filterErrorsContainerAttributes = $attributes;
return $new;
}
| public self filterFormAttributes ( array $attributes ) | ||
| $attributes | array | |
public function filterFormAttributes(array $attributes): self
{
$new = clone $this;
$new->filterFormAttributes = $attributes;
return $new;
}
| public self filterFormId ( string $id ) | ||
| $id | string | |
public function filterFormId(string $id): self
{
$new = clone $this;
$new->filterFormId = $id;
return $new;
}
| protected \Yiisoft\Data\Reader\ReadableDataInterface getDataReader ( ) |
final protected function getDataReader(): ReadableDataInterface
{
if ($this->dataReader === null) {
throw new DataReaderNotSetException();
}
return $this->dataReader;
}
| protected integer getDefaultPageSize ( ) |
final protected function getDefaultPageSize(): int
{
$dataReader = $this->getDataReader();
$pageSize = $dataReader instanceof PaginatorInterface
? $dataReader->getPageSize()
: PaginatorInterface::DEFAULT_PAGE_SIZE;
if (is_int($this->pageSizeConstraint)) {
return $pageSize <= $this->pageSizeConstraint
? $pageSize
: $this->pageSizeConstraint;
}
if (is_array($this->pageSizeConstraint)) {
return in_array($pageSize, $this->pageSizeConstraint, true)
? $pageSize
: $this->pageSizeConstraint[0];
}
return $pageSize;
}
| protected string getNoResultsContent ( ) |
final protected function getNoResultsContent(): string
{
$text = $this->translator->translate(
$this->noResultsText,
category: $this->translationCategory,
);
return str_replace('{text}', $text, $this->noResultsTemplate);
}
Defined in: Yiisoft\Yii\DataView\BaseListView::header()
Return new instance with the header for the grid.
| public static header ( string $content ) | ||
| $content | string |
The header of the grid. {@see \Yiisoft\Yii\DataView\headerAttributes} |
final public function header(string $content): static
{
$new = clone $this;
$new->header = $content;
return $new;
}
Defined in: Yiisoft\Yii\DataView\BaseListView::headerAttributes()
Return new instance with the HTML attributes for the header.
| public static headerAttributes ( array $attributes ) | ||
| $attributes | array |
Attribute values indexed by attribute names. |
final public function headerAttributes(array $attributes): static
{
$new = clone $this;
$new->headerAttributes = $attributes;
return $new;
}
Return new instance with the HTML attributes for the th tag.
| public self headerCellAttributes ( array $attributes ) | ||
| $attributes | array |
The tag attributes in terms of name-value pairs. |
| return | self |
New instance with the header cell attributes. |
|---|---|---|
public function headerCellAttributes(array $attributes): self
{
$new = clone $this;
$new->headerCellAttributes = $attributes;
return $new;
}
Defined in: Yiisoft\Yii\DataView\BaseListView::headerClass()
| public static headerClass ( \BackedEnum|string|null $class ) | ||
| $class | \BackedEnum|string|null | |
public function headerClass(BackedEnum|string|null ...$class): static
{
$new = clone $this;
$new->headerAttributes['class'] = [];
Html::addCssClass($new->headerAttributes, $class);
return $new;
}
Return new instance with the HTML attributes for the header row.
| public self headerRowAttributes ( array $attributes ) | ||
| $attributes | array |
Attribute values indexed by attribute names. |
| return | self |
New instance with the header row attributes. |
|---|---|---|
public function headerRowAttributes(array $attributes): self
{
$new = clone $this;
$new->headerRowAttributes = $attributes;
return $new;
}
Defined in: Yiisoft\Yii\DataView\BaseListView::headerTag()
| public static headerTag ( ?string $tag ) | ||
| $tag | ?string | |
final public function headerTag(?string $tag): static
{
if ($tag === '') {
throw new InvalidArgumentException('Tag name cannot be empty.');
}
$new = clone $this;
$new->headerTag = $tag;
return $new;
}
Defined in: Yiisoft\Yii\DataView\BaseListView::id()
Returns a new instance with the id of the grid view, detail view, or list view.
| public static id ( string $id ) | ||
| $id | string |
The ID of the grid view, detail view, or list view. |
final public function id(string $id): static
{
$new = clone $this;
$new->containerAttributes['id'] = $id;
return $new;
}
| public static ignoreMissingPage ( boolean $enabled ) | ||
| $enabled | boolean | |
final public function ignoreMissingPage(bool $enabled): static
{
$new = clone $this;
$new->ignoreMissingPage = $enabled;
return $new;
}
Whether to keep the current page when sorting is changed.
| public self keepPageOnSort ( boolean $enabled = true ) | ||
| $enabled | boolean |
Whether to keep the current page. |
| return | self |
New instance with the keep page on sort setting. |
|---|---|---|
public function keepPageOnSort(bool $enabled = true): self
{
$new = clone $this;
$new->keepPageOnSort = $enabled;
return $new;
}
Defined in: Yiisoft\Yii\DataView\BaseListView::keysetPaginationConfig()
Set configuration for keyset pagination widget.
| public static keysetPaginationConfig ( array $config ) | ||
| $config | array |
Widget config. |
final public function keysetPaginationConfig(array $config): static
{
$new = clone $this;
$new->keysetPaginationConfig = $config;
return $new;
}
Defined in: Yiisoft\Yii\DataView\BaseListView::layout()
Returns a new instance with the layout of the grid view, and list view.
| public static layout ( string $view ) | ||
| $view | string |
The template that determines how different sections of the grid view, list view. Should be organized. The following tokens will be replaced with the corresponding section contents:
|
final public function layout(string $view): static
{
$new = clone $this;
$new->layout = $view;
return $new;
}
| protected array makeFilters ( ) |
protected function makeFilters(): array
{
$columns = $this->getColumns();
$renderers = $this->getColumnRenderers();
$validationResult = new ValidationResult();
$context = new MakeFilterContext($validationResult, $this->urlParameterProvider);
$filters = [];
foreach ($columns as $i => $column) {
if ($renderers[$i] instanceof FilterableColumnRendererInterface) {
try {
$filter = $renderers[$i]->makeFilter($column, $context);
} catch (IncorrectValueException) {
$filters = null;
break;
}
if ($filter !== null) {
$filters[] = $filter;
}
}
}
return [$filters, $validationResult];
}
Defined in: Yiisoft\Yii\DataView\BaseListView::multiSort()
| public static multiSort ( boolean $enable = true ) | ||
| $enable | boolean | |
final public function multiSort(bool $enable = true): static
{
$new = clone $this;
$new->multiSort = $enable;
return $new;
}
| public self noResultsCellAttributes ( array $attributes ) | ||
| $attributes | array | |
public function noResultsCellAttributes(array $attributes): self
{
$new = clone $this;
$new->noResultsCellAttributes = $attributes;
return $new;
}
| public static noResultsTemplate ( string $template ) | ||
| $template | string | |
final public function noResultsTemplate(string $template): static
{
$new = clone $this;
$new->noResultsTemplate = $template;
return $new;
}
| public static noResultsText ( string $text ) | ||
| $text | string | |
final public function noResultsText(string $text): static
{
$new = clone $this;
$new->noResultsText = $text;
return $new;
}
Defined in: Yiisoft\Yii\DataView\BaseListView::offsetPaginationConfig()
Set configuration for offset pagination widget.
| public static offsetPaginationConfig ( array $config ) | ||
| $config | array |
Widget config. |
final public function offsetPaginationConfig(array $config): static
{
$new = clone $this;
$new->offsetPaginationConfig = $config;
return $new;
}
| public static pageNotFoundExceptionCallback ( ?callable $callback ) | ||
| $callback | ?callable | |
final public function pageNotFoundExceptionCallback(?callable $callback): static
{
$new = clone $this;
$new->pageNotFoundExceptionCallback = $callback;
return $new;
}
Defined in: Yiisoft\Yii\DataView\BaseListView::pageParameterName()
Return a new instance with the name of argument or query parameter for page.
| public static pageParameterName ( string $name ) | ||
| $name | string |
The name of argument or query parameter for page. |
final public function pageParameterName(string $name): static
{
$new = clone $this;
$new->urlConfig = $this->urlConfig->withPageParameterName($name);
return $new;
}
Defined in: Yiisoft\Yii\DataView\BaseListView::pageParameterType()
Creates a new instance with the specified page parameter type.
| public static pageParameterType ( \Yiisoft\Yii\DataView\Url\UrlParameterType $type ) | ||
| $type | \Yiisoft\Yii\DataView\Url\UrlParameterType |
The new page parameter type. |
| return | Yiisoft\Yii\DataView\BaseListView |
A new instance with the updated page parameter type. |
|---|---|---|
final public function pageParameterType(UrlParameterType $type): static
{
$new = clone $this;
$new->urlConfig = $this->urlConfig->withPageParameterType($type);
return $new;
}
Defined in: Yiisoft\Yii\DataView\BaseListView::pageSizeAttributes()
Returns a new instance with the HTML attributes for page size wrapper tag.
| public static pageSizeAttributes ( array $attributes ) | ||
| $attributes | array |
Attribute values indexed by attribute names. |
final public function pageSizeAttributes(array $attributes): static
{
$new = clone $this;
$new->pageSizeAttributes = $attributes;
return $new;
}
Defined in: Yiisoft\Yii\DataView\BaseListView::pageSizeConstraint()
Get a new instance with a page size constraint set.
| public static pageSizeConstraint ( array|boolean|integer $pageSizeConstraint ) | ||
| $pageSizeConstraint | array|boolean|integer |
Page size constraint.
|
| return | Yiisoft\Yii\DataView\BaseListView |
New instance. |
|---|---|---|
final public function pageSizeConstraint(array|int|bool $pageSizeConstraint): static
{
$new = clone $this;
$new->pageSizeConstraint = $pageSizeConstraint;
return $new;
}
Defined in: Yiisoft\Yii\DataView\BaseListView::pageSizeParameterName()
Return a new instance with the name of argument or query parameter for page size.
| public static pageSizeParameterName ( string $name ) | ||
| $name | string |
The name of argument or query parameter for page size. |
final public function pageSizeParameterName(string $name): static
{
$new = clone $this;
$new->urlConfig = $this->urlConfig->withPageSizeParameterName($name);
return $new;
}
Defined in: Yiisoft\Yii\DataView\BaseListView::pageSizeParameterType()
Creates a new instance with the specified page size parameter type.
| public static pageSizeParameterType ( \Yiisoft\Yii\DataView\Url\UrlParameterType $type ) | ||
| $type | \Yiisoft\Yii\DataView\Url\UrlParameterType |
The new page size parameter type. |
| return | Yiisoft\Yii\DataView\BaseListView |
A new instance with the updated page size parameter type. |
|---|---|---|
final public function pageSizeParameterType(UrlParameterType $type): static
{
$new = clone $this;
$new->urlConfig = $this->urlConfig->withPageSizeParameterType($type);
return $new;
}
Defined in: Yiisoft\Yii\DataView\BaseListView::pageSizeTag()
| public static pageSizeTag ( ?string $tag ) | ||
| $tag | ?string | |
final public function pageSizeTag(?string $tag): static
{
if ($tag === '') {
throw new InvalidArgumentException('Tag name cannot be empty.');
}
$new = clone $this;
$new->pageSizeTag = $tag;
return $new;
}
Defined in: Yiisoft\Yii\DataView\BaseListView::pageSizeTemplate()
Returns a new instance with the page size template.
| public static pageSizeTemplate ( string|null $template ) | ||
| $template | string|null |
The HTML content to be displayed as the page size control. If you don't want to show
control, you may set it with an empty string or The following tokens will be replaced with the corresponding values:
|
final public function pageSizeTemplate(?string $template): static
{
$new = clone $this;
$new->pageSizeTemplate = $template;
return $new;
}
| public static pageSizeWidget ( ?\Yiisoft\Yii\DataView\PageSize\PageSizeWidgetInterface $widget ) | ||
| $widget | ?\Yiisoft\Yii\DataView\PageSize\PageSizeWidgetInterface | |
final public function pageSizeWidget(?PageSizeWidgetInterface $widget): static
{
$new = clone $this;
$new->pageSizeWidget = $widget;
return $new;
}
| public static paginationWidget ( ?\Yiisoft\Yii\DataView\Pagination\PaginationWidgetInterface $widget ) | ||
| $widget | ?\Yiisoft\Yii\DataView\Pagination\PaginationWidgetInterface | |
final public function paginationWidget(?PaginationWidgetInterface $widget): static
{
$new = clone $this;
$new->paginationWidget = $widget;
return $new;
}
| protected array prepareOrder ( array $order ) | ||
| $order | array | |
protected function prepareOrder(array $order): array
{
$columns = $this->getColumns();
$renderers = $this->getColumnRenderers();
$allowedProperties = [];
foreach ($columns as $i => $column) {
if ($renderers[$i] instanceof SortableColumnRendererInterface) {
$allowedProperties[] = $renderers[$i]->getOrderProperties($column);
}
}
$allowedProperties = array_merge(...$allowedProperties);
return array_filter(
$order,
static fn(string $property): bool => in_array($property, $allowedProperties, true),
ARRAY_FILTER_USE_KEY,
);
}
Defined in: Yiisoft\Yii\DataView\BaseListView::prepend()
Returns a new instance with HTML content to be added after the opening container tag.
| public static prepend ( string|\Stringable $prepend ) | ||
| $prepend | string|\Stringable |
The HTML content to be prepended. |
final public function prepend(string|Stringable ...$prepend): static
{
$new = clone $this;
$new->prepend = implode('', $prepend);
return $new;
}
| public static previousPageParameterName ( string $name ) | ||
| $name | string | |
final public function previousPageParameterName(string $name): static
{
$new = clone $this;
$new->urlConfig = $this->urlConfig->withPreviousPageParameterName($name);
return $new;
}
Defined in: Yiisoft\Yii\DataView\BaseListView::previousPageParameterType()
Creates a new instance with the specified previous page parameter type.
| public static previousPageParameterType ( \Yiisoft\Yii\DataView\Url\UrlParameterType $type ) | ||
| $type | \Yiisoft\Yii\DataView\Url\UrlParameterType |
The new previous page parameter type. |
| return | Yiisoft\Yii\DataView\BaseListView |
A new instance with the updated previous page parameter type. |
|---|---|---|
final public function previousPageParameterType(UrlParameterType $type): static
{
$new = clone $this;
$new->urlConfig = $this->urlConfig->withPreviousPageParameterType($type);
return $new;
}
Defined in: Yiisoft\Yii\DataView\BaseListView::render()
| public string render ( ) |
final public function render(): string
{
[$filters, $filterValidationResult] = $this->makeFilters();
[$preparedDataReader, $items] = $filters === null
? [null, []]
: $this->prepareDataReaderAndItems($filters);
$content = trim(
strtr(
$this->layout,
[
'{header}' => $this->renderHeader(),
'{toolbar}' => $this->toolbar,
'{items}' => $this->renderItems($items, $filterValidationResult, $preparedDataReader),
'{summary}' => $this->renderSummary($preparedDataReader),
'{pager}' => $this->renderPagination($preparedDataReader),
'{pageSize}' => $this->renderPageSize($preparedDataReader),
],
),
);
if ($this->prepend !== '') {
$content = $this->prepend . "\n" . $content;
}
if ($this->append !== '') {
$content .= "\n" . $this->append;
}
return $this->containerTag === null
? $content
: Html::tag($this->containerTag, "\n" . $content . "\n", $this->containerAttributes)
->encode(false)
->render();
}
| protected string renderItems ( array $items, \Yiisoft\Validator\Result $filterValidationResult, ?\Yiisoft\Data\Reader\ReadableDataInterface $preparedDataReader ) | ||
| $items | array | |
| $filterValidationResult | \Yiisoft\Validator\Result | |
| $preparedDataReader | ?\Yiisoft\Data\Reader\ReadableDataInterface | |
protected function renderItems(
array $items,
ValidationResult $filterValidationResult,
?ReadableDataInterface $preparedDataReader,
): string {
$columns = $this->getColumns();
$renderers = $this->getColumnRenderers();
$blocks = [];
$filtersForm = '';
$dataReader = $this->getDataReader();
if ($preparedDataReader instanceof PaginatorInterface) {
$pageToken = $preparedDataReader->isOnFirstPage() ? null : $preparedDataReader->getToken();
$pageSize = $preparedDataReader->getPageSize();
if ($pageSize === $this->getDefaultPageSize()) {
$pageSize = null;
}
} else {
$pageToken = null;
$pageSize = null;
}
$globalContext = new GlobalContext(
$this->getSort($dataReader),
$this->getSort($preparedDataReader),
$this->getAllowedPropertiesForSort(),
$this->sortableHeaderClass,
$this->sortableHeaderPrepend,
$this->sortableHeaderAppend,
$this->sortableHeaderAscClass,
$this->sortableHeaderAscPrepend,
$this->sortableHeaderAscAppend,
$this->sortableHeaderDescClass,
$this->sortableHeaderDescPrepend,
$this->sortableHeaderDescAppend,
$this->sortableLinkAttributes,
$this->sortableLinkAscClass,
$this->sortableLinkDescClass,
$this->keepPageOnSort ? $pageToken : null,
$pageSize,
$this->multiSort,
$this->urlConfig,
$this->urlCreator,
$this->translator,
$this->translationCategory,
);
$tags = [];
$hasFilters = false;
$filterContext = new FilterContext(
formId: $this->filterFormId,
validationResult: $filterValidationResult,
cellInvalidClass: $this->filterCellInvalidClass,
errorsContainerAttributes: $this->filterErrorsContainerAttributes,
urlParameterProvider: $this->urlParameterProvider,
);
foreach ($columns as $i => $column) {
$cell = $renderers[$i] instanceof FilterableColumnRendererInterface
? $renderers[$i]->renderFilter($column, new Cell(attributes: $this->filterCellAttributes), $filterContext)
: null;
if ($cell === null) {
$tags[] = Html::td(' ')->encode(false);
} else {
$tags[] = Html::td(attributes: $cell->getAttributes())
->content(...$cell->getContent())
->encode($cell->shouldEncode())
->doubleEncode($cell->shouldDoubleEncode());
$hasFilters = true;
}
}
if ($hasFilters) {
$sort = $this->urlParameterProvider->get(
$this->urlConfig->getSortParameterName(),
$this->urlConfig->getSortParameterType(),
);
$url = $this->urlCreator === null ? '' : call_user_func_array(
$this->urlCreator,
UrlParametersFactory::create(
null,
$this->urlConfig->getPageSizeParameterType() === UrlParameterType::Path ? $pageSize : null,
$this->urlConfig->getSortParameterType() === UrlParameterType::Path ? $sort : null,
$this->urlConfig,
),
);
$content = [Html::submitButton()];
if (!empty($pageSize) && $this->urlConfig->getPageSizeParameterType() === UrlParameterType::Query) {
$content[] = Html::hiddenInput($this->urlConfig->getPageSizeParameterName(), $pageSize);
}
if (!empty($sort) && $this->urlConfig->getSortParameterType() === UrlParameterType::Query) {
$content[] = Html::hiddenInput($this->urlConfig->getSortParameterName(), $sort);
}
$formAttributes = $this->filterFormAttributes;
$formAttributes['id'] = $filterContext->formId;
Html::addCssStyle($formAttributes, 'display:none');
$filtersForm = Html::form($url, 'GET', $formAttributes)
->content(...$content)
->render();
$filterRow = Html::tr()->cells(...$tags);
} else {
$filterRow = null;
}
if ($this->columnGrouping) {
$tags = [];
foreach ($columns as $i => $column) {
$cell = $renderers[$i]->renderColumn($column, new Cell(), $globalContext);
$tags[] = Html::col($cell->getAttributes());
}
$blocks[] = Html::colgroup()->columns(...$tags)->render();
}
if ($this->isHeaderEnabled) {
$tags = [];
foreach ($columns as $i => $column) {
$cell = $renderers[$i]->renderHeader($column, new Cell($this->headerCellAttributes), $globalContext);
$tags[] = $cell === null
? Html::th(' ')->encode(false)
: Html::th(attributes: $cell->getAttributes())
->content(...$cell->getContent())
->encode($cell->shouldEncode())
->doubleEncode($cell->shouldDoubleEncode());
}
$headerRow = Html::tr($this->headerRowAttributes)->cells(...$tags);
$thead = Html::thead()->rows($headerRow);
if ($filterRow !== null) {
$thead = $thead->addRows($filterRow);
}
$blocks[] = $thead->render();
}
if ($this->isFooterEnabled) {
$tags = [];
foreach ($columns as $i => $column) {
$cell = $renderers[$i]->renderFooter(
$column,
(new Cell())->content(' ')->encode(false),
$globalContext,
);
$tags[] = Html::td(attributes: $cell->getAttributes())
->content(...$cell->getContent())
->encode($cell->shouldEncode())
->doubleEncode($cell->shouldDoubleEncode());
}
$footerRow = Html::tr($this->footerRowAttributes)->cells(...$tags);
$blocks[] = Html::tfoot()->rows($footerRow)->render();
}
$rows = [];
$index = 0;
foreach ($items as $key => $value) {
if ($this->beforeRowCallback !== null) {
/**
* @psalm-suppress InvalidArgument
*/
$row = ($this->beforeRowCallback)($value, $key, $index, $this);
if (!empty($row)) {
$rows[] = $row;
}
}
$tags = [];
foreach ($columns as $i => $column) {
$context = new DataContext($preparedDataReader, $column, $value, $key, $index);
$cell = $renderers[$i]->renderBody($column, new Cell($this->bodyCellAttributes), $context);
$tags[] = $cell->isEmptyContent()
? Html::td($this->emptyCell, $this->emptyCellAttributes)->encode(false)
: Html::td(attributes: $this->prepareBodyCellAttributes($cell->getAttributes(), $context))
->content(...$cell->getContent())
->encode($cell->shouldEncode())
->doubleEncode($cell->shouldDoubleEncode());
}
$bodyRowAttributes = $this->prepareBodyRowAttributes(
$this->bodyRowAttributes,
new BodyRowContext($value, $key, $index),
);
$rows[] = Html::tr($bodyRowAttributes)->cells(...$tags);
if ($this->afterRowCallback !== null) {
/**
* @psalm-suppress InvalidArgument
*/
$row = ($this->afterRowCallback)($value, $key, $index, $this);
if (!empty($row)) {
$rows[] = $row;
}
}
$index++;
}
$blocks[] = empty($rows)
? Html::tbody($this->tbodyAttributes)
->rows(Html::tr()->cells($this->renderEmptyCell(count($columns))))
->render()
: Html::tbody($this->tbodyAttributes)->rows(...$rows)->render();
$caption = $this->caption === null
? ''
: Html::tag('caption', $this->caption) . "\n";
return
$filtersForm
. Html::tag('table', attributes: $this->tableAttributes)->open()
. "\n"
. $caption
. implode("\n", $blocks)
. "\n"
. '</table>';
}
Defined in: Yiisoft\Yii\DataView\BaseListView::sortParameterName()
Creates a new instance with the specified sort parameter name.
| public static sortParameterName ( string $name ) | ||
| $name | string |
The new sort parameter name. |
| return | Yiisoft\Yii\DataView\BaseListView |
A new instance with the updated sort parameter name. |
|---|---|---|
final public function sortParameterName(string $name): static
{
$new = clone $this;
$new->urlConfig = $this->urlConfig->withSortParameterName($name);
return $new;
}
Defined in: Yiisoft\Yii\DataView\BaseListView::sortParameterType()
Creates a new instance with the specified sort parameter type.
| public static sortParameterType ( \Yiisoft\Yii\DataView\Url\UrlParameterType $type ) | ||
| $type | \Yiisoft\Yii\DataView\Url\UrlParameterType |
The new sort parameter type. |
| return | Yiisoft\Yii\DataView\BaseListView |
A new instance with the updated sort parameter type. |
|---|---|---|
final public function sortParameterType(UrlParameterType $type): static
{
$new = clone $this;
$new->urlConfig = $this->urlConfig->withSortParameterType($type);
return $new;
}
Return new instance with the content to be appended to sortable column headers.
| public self sortableHeaderAppend ( string|\Stringable $content ) | ||
| $content | string|\Stringable |
The content to append. |
| return | self |
New instance with the sortable header append content. |
|---|---|---|
public function sortableHeaderAppend(string|Stringable $content): self
{
$new = clone $this;
$new->sortableHeaderAppend = $content;
return $new;
}
Return new instance with the content to be appended to ascending sorted column headers.
| public self sortableHeaderAscAppend ( string|\Stringable $content ) | ||
| $content | string|\Stringable |
The content to append. |
| return | self |
New instance with the sortable header ascending append content. |
|---|---|---|
public function sortableHeaderAscAppend(string|Stringable $content): self
{
$new = clone $this;
$new->sortableHeaderAscAppend = $content;
return $new;
}
Return new instance with the content to be prepended to ascending sorted column headers.
| public self sortableHeaderAscPrepend ( string|\Stringable $content ) | ||
| $content | string|\Stringable |
The content to prepend. |
| return | self |
New instance with the sortable header ascending prepend content. |
|---|---|---|
public function sortableHeaderAscPrepend(string|Stringable $content): self
{
$new = clone $this;
$new->sortableHeaderAscPrepend = $content;
return $new;
}
Return new instance with the content to be appended to descending sorted column headers.
| public self sortableHeaderDescAppend ( string|\Stringable $content ) | ||
| $content | string|\Stringable |
The content to append. |
| return | self |
New instance with the sortable header descending append content. |
|---|---|---|
public function sortableHeaderDescAppend(string|Stringable $content): self
{
$new = clone $this;
$new->sortableHeaderDescAppend = $content;
return $new;
}
Return new instance with the content to be prepended to descending sorted column headers.
| public self sortableHeaderDescPrepend ( string|\Stringable $content ) | ||
| $content | string|\Stringable |
The content to prepend. |
| return | self |
New instance with the sortable header descending prepend content. |
|---|---|---|
public function sortableHeaderDescPrepend(string|Stringable $content): self
{
$new = clone $this;
$new->sortableHeaderDescPrepend = $content;
return $new;
}
Return new instance with the content to be prepended to sortable column headers.
| public self sortableHeaderPrepend ( string|\Stringable $content ) | ||
| $content | string|\Stringable |
The content to prepend. |
| return | self |
New instance with the sortable header prepend content. |
|---|---|---|
public function sortableHeaderPrepend(string|Stringable $content): self
{
$new = clone $this;
$new->sortableHeaderPrepend = $content;
return $new;
}
Return new instance with the HTML attributes for a link in sortable columns' headers.
| public self sortableLinkAttributes ( array $attributes ) | ||
| $attributes | array |
The tag attributes in terms of name-value pairs. |
| return | self |
New instance with the sortable link attributes. |
|---|---|---|
public function sortableLinkAttributes(array $attributes): self
{
$new = clone $this;
$new->sortableLinkAttributes = $attributes;
return $new;
}
Defined in: Yiisoft\Yii\DataView\BaseListView::summaryAttributes()
Returns a new instance with the HTML attributes for summary wrapper tag.
| public static summaryAttributes ( array $attributes ) | ||
| $attributes | array |
Attribute values indexed by attribute names. |
final public function summaryAttributes(array $attributes): static
{
$new = clone $this;
$new->summaryAttributes = $attributes;
return $new;
}
Defined in: Yiisoft\Yii\DataView\BaseListView::summaryTag()
| public static summaryTag ( ?string $tag ) | ||
| $tag | ?string | |
final public function summaryTag(?string $tag): static
{
if ($tag === '') {
throw new InvalidArgumentException('Tag name cannot be empty.');
}
$new = clone $this;
$new->summaryTag = $tag;
return $new;
}
Defined in: Yiisoft\Yii\DataView\BaseListView::summaryTemplate()
Returns a new instance with the summary template.
| public static summaryTemplate ( string|null $template ) | ||
| $template | string|null |
The HTML content to be displayed as the summary. If you don't want to show the summary, you may set it with an empty string or null. The following tokens will be replaced with the corresponding values:
|
final public function summaryTemplate(?string $template): static
{
$new = clone $this;
$new->summaryTemplate = $template;
return $new;
}
Return new instance with the HTML attributes for the table tag.
| public self tableAttributes ( array $attributes ) | ||
| $attributes | array |
The tag attributes in terms of name-value pairs. |
| return | self |
New instance with the table attributes. |
|---|---|---|
public function tableAttributes(array $attributes): self
{
$new = clone $this;
$new->tableAttributes = $attributes;
return $new;
}
Replace current table tag CSS classes with a new set of classes.
| public self tableClass ( string|null $class ) | ||
| $class | string|null |
One or many CSS classes. |
| return | self |
New instance with the replaced table CSS classes. |
|---|---|---|
public function tableClass(?string ...$class): self
{
$new = clone $this;
$new->tableAttributes['class'] = array_filter($class, static fn($c) => $c !== null);
return $new;
}
Return new instance with the HTML attributes for the tbody tag.
| public self tbodyAttributes ( array $attributes ) | ||
| $attributes | array |
The tag attributes in terms of name-value pairs. |
| return | self |
New instance with the tbody attributes. |
|---|---|---|
public function tbodyAttributes(array $attributes): self
{
$new = clone $this;
$new->tbodyAttributes = $attributes;
return $new;
}
Replace current tbody tag CSS classes with a new set of classes.
| public self tbodyClass ( string|null $class ) | ||
| $class | string|null |
One or many CSS classes. |
| return | self |
New instance with the replaced tbody CSS classes. |
|---|---|---|
public function tbodyClass(?string ...$class): self
{
$new = clone $this;
$new->tbodyAttributes['class'] = array_filter($class, static fn($c) => $c !== null);
return $new;
}
Defined in: Yiisoft\Yii\DataView\BaseListView::toolbar()
Return new instance with toolbar content.
| public static toolbar ( string $content ) | ||
| $content | string |
The toolbar content. |
final public function toolbar(string $content): static
{
$new = clone $this;
$new->toolbar = $content;
return $new;
}
Defined in: Yiisoft\Yii\DataView\BaseListView::urlArguments()
Return a new instance with arguments of the route.
| public static urlArguments ( array $arguments ) | ||
| $arguments | array |
Arguments of the route. |
final public function urlArguments(array $arguments): static
{
$new = clone $this;
$new->urlConfig = $this->urlConfig->withArguments($arguments);
return $new;
}
Defined in: Yiisoft\Yii\DataView\BaseListView::urlCreator()
| public static urlCreator ( ?callable $urlCreator ) | ||
| $urlCreator | ?callable | |
final public function urlCreator(?callable $urlCreator): static
{
$new = clone $this;
$new->urlCreator = $urlCreator;
return $new;
}
| public static urlParameterProvider ( Yiisoft\Yii\DataView\Url\UrlParameterProviderInterface $provider ) | ||
| $provider | Yiisoft\Yii\DataView\Url\UrlParameterProviderInterface | |
final public function urlParameterProvider(UrlParameterProviderInterface $provider): static
{
$new = clone $this;
$new->urlParameterProvider = $provider;
return $new;
}
Defined in: Yiisoft\Yii\DataView\BaseListView::urlQueryParameters()
Return a new instance with query parameters of the route.
| public static urlQueryParameters ( array $parameters ) | ||
| $parameters | array |
The query parameters of the route. |
final public function urlQueryParameters(array $parameters): static
{
$new = clone $this;
$new->urlConfig = $this->urlConfig->withQueryParameters($parameters);
return $new;
}
Signup or Login in order to comment.