Skip to content

Filters

Filters are declared as filter objects and mapped to methods on your listing component.

protected function filters(): array
{
    return [
        new TextFieldType('email', 'Email', 'filterEmail'),
    ];
}

protected function filterEmail(Builder $query): void
{
    if (! empty($this->activeFilters['email'])) {
        $query->where('email', 'like', '%'.$this->activeFilters['email'].'%');
    }
}

Incoming filter keys are whitelisted against declared filters before they are applied to the query.

Built-in Filter Types

  • TextFieldType
  • OptionsListType

Custom Filters

Custom filters must implement FilterTypeInterface:

interface FilterTypeInterface
{
    public function getName(): string;

    public function getLabel(): string;

    public function getCallbackFunction(): string;

    public function htmlOutput(): string;
}