Filters
When and how to add declarative filters to a server-side DataTable
What / When
Filters add a popover next to the search box. Use them on Doctrine server-side tables when users need structured criteria (status, date range, free text) beyond global search.
They do not apply to client-side inline datasets in this version.
Minimal Example
Declare filters on your AbstractDataTable:
use Pentiminax\UX\DataTables\Filter\ChoiceFilter;
use Pentiminax\UX\DataTables\Filter\TextFilter;
use Pentiminax\UX\DataTables\Model\Filters;
public function configureFilters(Filters $filters): Filters
{
return $filters
->add(TextFilter::new('email')->label('Email'))
->add(
ChoiceFilter::new('status')
->label('Status')
->options(['Draft' => 'draft', 'Published' => 'published'])
);
}
Or declare them on the class holding the data, with no configureFilters() at all:
use App\Enum\Status;
use Pentiminax\UX\DataTables\Attribute\DataTableFilter;
class User
{
#[DataTableFilter(options: ['label' => 'Email'])]
private string $email;
#[DataTableFilter(options: ['label' => 'Status'])]
private Status $status;
}
The filter class is guessed from the declared type, and a BackedEnum brings its own options along.
An int or a float gives a number range with optional min and max inputs.
To filter by a Doctrine association, list the target entities with EntityFilter:
use App\Entity\Category;
use Pentiminax\UX\DataTables\Filter\EntityFilter;
use Pentiminax\UX\DataTables\Filter\NumberRangeFilter;
$filters
->add(NumberRangeFilter::new('price')->label('Price'))
->add(EntityFilter::new('category')->entity(Category::class)->optionLabel('name'));
The entity list is loaded server-side and capped at 200 options. It is not an authorization boundary: restrict the rows themselves in the table query.
Pitfalls
Related
- Full API: Filters reference
- Recipe: Filters
- Server-Side Processing