0 follower

Final Class Yiisoft\Yii\DataView\Filter\Widget\DropdownFilter

InheritanceYiisoft\Yii\DataView\Filter\Widget\DropdownFilter » Yiisoft\Yii\DataView\Filter\Widget\FilterWidget » Yiisoft\Widget\Widget

Filter widget that renders a dropdown (select) input for filtering data.

Public Methods

Hide inherited methods

Method Description Defined By
addAttributes() Add a set of attributes to existing tag attributes. Yiisoft\Yii\DataView\Filter\Widget\DropdownFilter
addClass() Add one or more CSS classes to the Select tag. Yiisoft\Yii\DataView\Filter\Widget\DropdownFilter
attributes() Replace attributes with a new set. Yiisoft\Yii\DataView\Filter\Widget\DropdownFilter
class() Replace current Select tag CSS classes with a new set of classes. Yiisoft\Yii\DataView\Filter\Widget\DropdownFilter
optionsData() Sets the options data for the dropdown. Yiisoft\Yii\DataView\Filter\Widget\DropdownFilter
render() Renders the filter widget using the current context. Yiisoft\Yii\DataView\Filter\Widget\FilterWidget
renderFilter() Renders the dropdown filter with the given context. Yiisoft\Yii\DataView\Filter\Widget\DropdownFilter
withContext() Creates a new instance with the specified filter context. Yiisoft\Yii\DataView\Filter\Widget\FilterWidget

Method Details

Hide inherited methods

addAttributes() public method

Add a set of attributes to existing tag attributes.

Same named attributes are replaced.

See also \Yiisoft\Html\Tag\Select::addAttributes().

public self addAttributes ( array $attributes )
$attributes array

Name-value set of attributes. Example: ['class' => 'form-select', 'data-role' => 'filter']

return self

New instance with added attributes.

                public function addAttributes(array $attributes): self
{
    $new = clone $this;
    $new->select = $this->getSelect()->addAttributes($attributes);
    return $new;
}

            
addClass() public method

Add one or more CSS classes to the Select tag.

public self addClass ( \BackedEnum|string|null $class )
$class \BackedEnum|string|null

One or many CSS classes.

                public function addClass(BackedEnum|string|null ...$class): self
{
    $new = clone $this;
    $new->select = $this->getSelect()->addClass(...$class);
    return $new;
}

            
attributes() public method

Replace attributes with a new set.

See also \Yiisoft\Html\Tag\Select::attributes().

public self attributes ( array $attributes )
$attributes array

Name-value set of attributes. Example: ['class' => 'custom-select', 'required' => true]

return self

New instance with replaced attributes.

                public function attributes(array $attributes): self
{
    $new = clone $this;
    $new->select = $this->getSelect()->attributes($attributes);
    return $new;
}

            
class() public method

Replace current Select tag CSS classes with a new set of classes.

public self class ( \BackedEnum|string|null $class )
$class \BackedEnum|string|null

One or many CSS classes.

                public function class(BackedEnum|string|null ...$class): self
{
    $new = clone $this;
    $new->select = $this->getSelect()->class(...$class);
    return $new;
}

            
optionsData() public method

Sets the options data for the dropdown.

See also \Yiisoft\Html\Tag\Select::optionsData().

public self optionsData ( array $data, boolean $encode true, array[] $optionsAttributes = [], array[] $groupsAttributes = [] )
$data array

Options data. The array keys are option values, and the array values are the corresponding option labels. For option groups, use a nested array where the array value is an array of options. Example: `php [

'active' => 'Active',
'status' => [
    'pending' => 'Pending',
    'completed' => 'Completed',
],

] `

$encode boolean

Whether to HTML-encode option content. Set to false if your option labels contain HTML that should be rendered.

$optionsAttributes array[]

Array of option attribute sets indexed by option values. Example: ['active' => ['class' => 'highlight']]

$groupsAttributes array[]

Array of group attribute sets indexed by group labels. Example: ['status' => ['class' => 'main-group']]

return self

New instance with configured options.

                public function optionsData(
    array $data,
    bool $encode = true,
    array $optionsAttributes = [],
    array $groupsAttributes = [],
): self {
    $new = clone $this;
    $new->select = $this->getSelect()->optionsData($data, $encode, $optionsAttributes, $groupsAttributes);
    return $new;
}

            
render() public method

Defined in: Yiisoft\Yii\DataView\Filter\Widget\FilterWidget::render()

Renders the filter widget using the current context.

public string render ( )
return string

The rendered HTML for the filter input.

                final public function render(): string
{
    return $this->renderFilter($this->context);
}

            
renderFilter() public method

Renders the dropdown filter with the given context.

public string renderFilter ( Yiisoft\Yii\DataView\Filter\Widget\Context $context )
$context Yiisoft\Yii\DataView\Filter\Widget\Context

The filter context.

return string

The rendered HTML select element.

                public function renderFilter(Context $context): string
{
    $select = $this->getSelect()
        ->name($context->property)
        ->form($context->formId)
        ->attribute('onChange', 'this.form.submit()');
    if ($context->value !== null) {
        $select = $select->value($context->value);
    }
    return $select->render();
}

            
withContext() public method

Defined in: Yiisoft\Yii\DataView\Filter\Widget\FilterWidget::withContext()

Creates a new instance with the specified filter context.

public self withContext ( Yiisoft\Yii\DataView\Filter\Widget\Context $context )
$context Yiisoft\Yii\DataView\Filter\Widget\Context

The filter context containing property, value, and form data.

return self

New instance with the specified context.

                final public function withContext(Context $context): self
{
    $new = clone $this;
    $new->context = $context;
    return $new;
}