Warning: You are browsing the documentation for PrestaShop 1.7, which is outdated.
You might want to read an updated version of this page for the current version, PrestaShop 8. Read the updated version of this page
The most important part of a Grid definition is defining columns. PrestaShop already comes with a list of predefined column types that you can use in your own Grids.
<?php
// /modules/my-module/src/Grid/MyGridDefinitionFactory.php
namespace MyModule\Grid;
use PrestaShop\PrestaShop\Core\Grid\Definition\Factory\AbstractGridDefinitionFactory;
use PrestaShop\PrestaShop\Core\Grid\Column\Type\DataColumn;
use PrestaShop\PrestaShop\Core\Grid\Column\ColumnCollection;
use PrestaShop\PrestaShop\Core\Grid\Column\Type\Common\BulkActionColumn;
use PrestaShop\PrestaShop\Core\Grid\Action\Row\RowActionCollection;
use PrestaShop\PrestaShop\Core\Grid\Action\Row\Type\LinkRowAction;
use PrestaShop\PrestaShop\Core\Grid\Column\Type\Common\ActionColumn;
/**
* How to define the Grid's columns?
* You can adapt this example or look at the existing ones
* in PrestaShop's Core.
*/
class MyGridDefinitionFactory extends AbstractGridDefinitionFactory
{
/**
* {@inheritdoc}
*/
protected function getColumns()
{
return (new ColumnCollection())
->add(
(new BulkActionColumn('delete_stuff'))
->setOptions([
'bulk_field' => 'id_stuff',
])
)
->add(
(new DataColumn('id_stuff'))
->setName('ID')
->setOptions([
'field' => 'id_stuff',
])
)
->add(
(new ActionColumn('actions'))
->setName('Actions')
->setOptions([
'actions' => (new RowActionCollection())
->add(
(new LinkRowAction('delete'))
->setIcon('delete')
->setOptions([
'route' => 'delete_stuff',
'route_param_name' => 'stuffId',
'route_param_field' => 'id_stuff',
'confirm_message' => 'Delete selected item?',
])
),
])
)
;
}
}