Grids in Sylius are responsible for rendering lists of entities in the administration panel, such as products, customers, or orders.
You can customize grids declaratively in YAML or programmatically using event listeners.
If youβre new to Sylius grids, we recommend starting with the .
Why Customize a Grid?
Typical use cases include:
Removing or modifying fields
Changing or disabling filters
Adjusting grid actions (e.g., buttons)
Reordering items
Programmatically extending grids with PHP
YAML-Based Customizations
The recommended and most common way to customize grids in Sylius 2.0 is by editing the config/packages/_sylius.yaml file.
This reorders the fields top-to-bottom in the grid.
PHP-Based Customizations (via Events)
In Sylius 2.0, grids can also be extended programmatically. Each grid dispatches an event during configuration.
Example: Modifying the Product Grid in PHP
Letβs say we want to:
Remove the image field
Add a variantSelectionMethod field
<?php
namespace App\Grid;
use Sylius\Component\Grid\Event\GridDefinitionConverterEvent;
use Sylius\Component\Grid\Definition\Field;
final class AdminProductsGridListener
{
public function editFields(GridDefinitionConverterEvent $event): void
{
$grid = $event->getGrid();
$grid->removeField('image');
$variantSelection = Field::fromNameAndType('variantSelectionMethod', 'string');
$variantSelection->setLabel('Variant Selection');
$grid->addField($variantSelection);
}
}
Be careful not to re-add a field that already exists. Doing so will throw a LogicException.
These options improve pagination performance on large datasets (especially for databases with over 1M rows) but may increase the number of executed queries.
If your use case requires disabling them, you can override them per grid: