Create grid definition

From PrestaShop/PrestaShop · View interactive version

Create grid definition is an AI agent skill from the GitHub repository PrestaShop/PrestaShop. Create the grid definition for an entity listing: columns, row actions, bulk actions, filters class, and service registration. Covers everything needed to define the grid structure. The query builder is a separate skill (create-grid-query-builder). Trigger: "create grid definition for {Domain}".

How to use this skill

Skill file

create-grid-definition

Read @.ai/Component/Grid/CONTEXT.md for the factory trilogy (GridDefinitionFactory → GridDataFactory → GridFactory) and SearchCriteria patterns.

1. Grid Definition Factory

Create src/Core/Grid/Definition/Factory/{Domain}GridDefinitionFactory.php extending AbstractGridDefinitionFactory:

Reference: src/Core/Grid/Definition/Factory/TaxGridDefinitionFactory.php (simple), src/Core/Grid/Definition/Factory/ManufacturerGridDefinitionFactory.php (two grids)

2. Column types

| Column type | When to use | Notes |

|---|---|---|

| BulkActionColumn | Row selection checkbox | Always first column |

| DataColumn | Plain text (name, email, date) | Most common |

| ToggleColumn | Clickable boolean toggle (active status) | Requires AJAX toggle route |

| ImageColumn | Image thumbnail (logo) | |

| LinkColumn | Text with hyperlink | |

| PositionColumn | Drag handle for reordering | See create-position-column skill |

| ActionColumn | Row actions dropdown | Always last column |

See Grid/CONTEXT.md for column ordering and naming conventions.

3. Row actions and bulk actions

Row actions

Add in getRowActions():

```php

use PrestaShop\PrestaShop\Core\Grid\Definition\Factory\DeleteActionTrait;

class {Domain}GridDefinitionFactory extends AbstractGridDefinitionFactory

{

use DeleteActionTrait;

protected function getRowActions(): RowActionCollection

{

return (new RowActionCollection())

->add(/* edit LinkRowAction */)

->add($this->buildDeleteAction(

'admin_{domain}s_delete', // route

'{domain}Id', // route param name

'{domain}Id', // row field providing the value

));

}

}

```

Bulk actions

Add in getBulkActions():

Route names in actions must exactly match the routing YAML.

4. Filters

Filters are defined in the grid definition via getFilters(): FilterCollection (see Grid/CONTEXT.md for conventions). Each filter specifies:

5. {Domain}Filters class (SearchCriteria)

Create src/Core/Search/Filters/{Domain}Filters.php extending Filters:

class {Domain}Filters extends Filters
{
    protected $filterId = {Domain}GridDefinitionFactory::GRID_ID;

    public static function getDefaults(): array
    {
        return [
            'limit' => static::LIST_LIMIT,
            'offset' => 0,
            'orderBy' => 'id_{domain}',
            'sortOrder' => 'asc',
            'filters' => [],
        ];
    }
}

Reference: src/Core/Search/Filters/TaxFilters.php (simple)

6. Service registration

Register in DI YAML:

Rules

Conventions (column ordering, toggle route, Filters as SearchCriteria) are in Grid/CONTEXT.md. Skill-specific reminder:

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.