Creating a custom Bulk Action
In some cases, forcing the user to click a button for each item in a grid isn't practical. Fortunately, you can take advantage of built-in bulk actions. However, these may not always be sufficient and might need customization.
To do this, simply create your own bulk action template and register it inside the sylius_grid
.
In the template we will specify the button's icon to be export
and its colour to be orange
.
<div data-gb-custom-block data-tag="import" data-0='@SyliusUi/Macro/buttons.html.twig'></div>
<div data-gb-custom-block data-tag="set"></div>
{{ buttons.default(path, action.label, null, 'export', 'orange') }}
Now configure the new action's template:
sylius_grid:
templates:
bulk_action:
export: "@App/Grid/BulkAction/export.html.twig"
From now on, you can use your new bulk action type in the grid configuration!
Let's assume that you already have a route for exporting by injecting ids. Now, you can configure the grid action:
sylius_grid:
grids:
app_admin_product:
...
actions:
bulk:
export:
type: export
label: Export Data
options:
link:
route: app_admin_product_export
parameters:
format: csv
Last updated