Releases: Kreyu/data-table-bundle
v0.27.0
What's Changed
⚡ This release is all about icons and theming improvements.
- Added
IconColumnType
that renders an icon - Added
icon
option to baseActionType
to define an icon instead oficon_attr
- Added icon themes that support Bootstrap and Tabler icons, both via webfont and Symfony UX Icons 🚀 (see docs)
- Added
attributes
macro to thebase.html.twig
theme to render HTML attributes from an array (see docs) - Added
data_table_theme_block
Twig function to render a block through the theme hierarchy (see docs) - Changed the way themes are loaded - now each theme overrides the previous one, like in Symfony Form (see docs)
- Added
with_caret
option toDropdownActionType
to allow rendering the dropdown without a caret (see docs) - Improved built-in themes
- In multiple blocks, the
class
attribute gets merged instead of being overridden completely - The Bootstrap 5 and Tabler themes are now more consistent with each other
- Removed the
action_control_icon
block
- In multiple blocks, the
- Improved documentation about theming
- Added missing Catalan & Spanish translations by @davidnectarestudio in #183
Full Changelog: v0.26.2...v0.27.0
Icon Themes
You should set an additional icon theme based on the icon set you're using in the application:
- Bootstrap Icons
- Tabler Icons
- Generic
Icon themes are separate templates to allow using different icon sets.
Webfont icon themes render icons as <i>
elements with CSS classes.
For example, Bootstrap's check
icon will be rendered as <i class="bi bi-check"></i>
The UX icon themes refer to the Symfony UX Icons, which requires
the symfony/ux-icons
package. Each icon has to be imported to the project separately, for example:
symfony console ux:icon:import bi:check
When using the generic icons_webfont.html.twig
, you are expected to provide full icon class names manually,
for example bi bi-check
instead of simple check
.
Using the icons_ux.html.twig
enables you to use the locally stored icons, for example:
user-profile
will render icon fromassets/icons/user-profile.svg
admin:user-profile
will render icon fromassets/icons/admin/user-profile.svg
For more details about how UX icons are loaded, see Symfony UX Icons documentation.
Setting Action Icon
In actions, you should define the icon using the icon
option instead of icon_attr
:
use Kreyu\Bundle\DataTableBundle\Action\Type\ButtonActionType;
// Before 😒
// - unnecessary nesting
// - coupled to specific icon set
// - does not work with Symfony UX icons
$builder->addRowAction('status', ButtonActionType::class, [
'icon_attr' => [
'class' => 'ti ti-eye',
],
]);
// After 😎
// - simple option
// - icon set agnostic (kinda)
// - supports Symfony UX icons
$builder->addRowAction('status', ButtonActionType::class, [
'icon' => 'eye',
]);
You can still use icon_attr
to define additional attributes for the icon, like class
:
use Kreyu\Bundle\DataTableBundle\Action\Type\ButtonActionType;
$builder->addRowAction('status', ButtonActionType::class, [
'icon' => 'eye',
'icon_attr' => [
'class' => 'text-primary',
],
]);
New Contributors
- @davidnectarestudio made their first contribution in #183
Sponsoring
Do you like the bundle and find it useful? The "Sponsor" button is now available for the repository!
Thank you for all your support.
v0.26.2
v0.26.1
What's Changed
This small release fixes the batch actions not working properly since 0.26.0 (#178). The URLs of the actions were not properly updated with the selected identifiers. The batch Stimulus controller was updated, therefore, remember to rebuild the assets if you're using build system.
Full Changelog: v0.26.0...v0.26.1
v0.26.0
What's Changed
Caution
This release contains breaking changes and deprecations.
Breaking Changes
- Renamed action types Twig block suffix from
value
tocontrol
by @alexandre-castelain (#163):
{# Before #}
{% block action_value %}{% endblock %}
{% block action_link_value %}{% endblock %}
{% block action_button_value %}{% endblock %}
{% block action_form_value %}{% endblock %}
{# After #}
{% block action_control %}{% endblock %}
{% block action_link_control %}{% endblock %}
{% block action_button_control %}{% endblock %}
{% block action_form_control %}{% endblock %}
This also includes custom action types with their own Twig blocks.
Deprecations
FormColumnType
is now deprecated. No replacement available.
Features
- Added dropdown action type - by @alexandre-castelain - see docs
- Added modal action type - by @alexandre-castelain (#110, #170) - see docs
- Added German translations - by @creiner (#156)
- Added HTML column type - see docs
- The column
value_translation_parameters
option now acceptscallable
value:
$builder->addColumn('firstName', options: [
'value_translation_parameters' => function (string $firstName, User $user) {
return [...];
},
]);
- The column value view now contains two additional variables - itself as
column
and its name asname
- Columns having
TranslatableInterface
as value is now automatically translated in export:
// Assume this data tables displays User entities
use Symfony\Contracts\Translation\TranslatableInterface;
use Symfony\Component\Translation\TranslatableMessage;
class User
{
public function __construct(
public TranslatableInterface $firstName,
) {
}
}
// This column displays User's first name and is exportable
$builder->addColumn('firstName', options: ['export' => true]);
// The row displays a User of name "John"
$rowView = new ValueRowView(data: new User(firstName: new TranslatableMessage('John'));
// Then export's ColumnValueView will be like so:
$view = $column->createExportValueView($rowView);
$view->vars['data']; // object(TranslatableMessage)
$view->vars['value']; // string(4) "John"
- The export value view now contains
data
variable, similar to regular value view, that represents value returned by property path or agetter
option, not formatted by theformatter
option:
// Assume this data tables displays User entities
use Kreyu\Bundle\DataTableBundle\ValueRowView;
use Kreyu\Bundle\DataTableBundle\Column\ColumnValueView;
class User
{
public function __construct(
public string $firstName,
) {
}
}
// This column displays User's first name and is exportable
$builder->addColumn('firstName', options: ['export' => true]);
// The row displays a User of name "John"
$rowView = new ValueRowView(data: new User(firstName: 'John'));
// Then export's ColumnValueView will be like so:
$view = $column->createExportValueView($rowView);
$view->vars['data']; // object(User)
$view->vars['value'] // string(4) "John"
Bug Fixes
- The Doctrine ORM filter types now properly allows overwriting the supported operators via option - by @alexandre-castelain (#168):
$builder->addFilter('id', NumericFilterType::class, [
'supported_operators' => [Operator::Equals, Operator::Contains],
'operator_selectable' => true,
]);
- The default property path inherited from column name is now properly set in column config (#148):
$builder->addColumn('firstName');
// Before:
$builder->getColumn('firstName')->getPropertyPath(); // null
$builder->getColumn('firstName')->getColumnConfig()->getPropertyPath(); // null
// After:
(string) $builder->getColumn('firstName')->getPropertyPath(); // string(9) "firstName"
(string) $dataTable->getColumn('firstName')->getConfig()->getPropertyPath(); // string(9) "firstName"
- The default sort property path inherited from column name is now properly set in column config (#149):
$builder->addColumn('firstName', options: ['sort' => true]);
// Before:
$builder->getColumn('firstName')->getSortPropertyPath(); // null
$builder->getColumn('firstName')->getColumnConfig()->getSortPropertyPath(); // null
// After:
(string) $builder->getColumn('firstName')->getSortPropertyPath(); // string(9) "firstName"
(string) $dataTable->getColumn('firstName')->getConfig()->getSortPropertyPath(); // string(9) "firstName"
- Setting the different column label for export is now properly respected (#147):
$builder->addColumn('name', TextColumnType::class, [
'export' => [
'label' => 'Full name',
],
]);
- Columns now inherit the
header_translation_domain
andvalue_translation_domain
options in export properly:
// Export will use column value translation domain and parameters:
$builder->addColumn('firstName', options: [
'value_translation_domain' => 'user',
'value_translation_parameters' => ['%first_name%' => 'John'];
]);
// This however, can be overwritten for export:
$builder->addColumn('firstName', options: [
'value_translation_domain' => 'user',
'value_translation_parameters' => ['%first_name%' => 'John'];
'export' => [
'value_translation_domain' => 'export_user',
'value_translation_parameters' => ['%first_name%' => 'Jane'];
]
]);
- Actions of the same name, but different context (global, row, batch) now use different ID of the confirmation modal:
// Assuming that the data table name is "user"
$builder
->addAction('foo', options: ['confirmation' => true])
->addRowAction('foo', options: ['confirmation' => true])
->addBatchAction('foo', options: ['confirmation' => true]);
Before, global and batch action confirmation modal would have the same ID: user-action-confirmation-foo
, which will result in invalid HTML. Now, the IDs will be different, using the new patterns:
- for global and batch action:
[data table name]--[context]-action--[action name]--confirmation
- for row action:
[data table name]--[context]-action--[action name]--confirmation--[row index]
Therefore:
- for global action, it will be
user--global-action--foo--confirmation
- for row action, it will be
user--row-action--foo--confirmation-0
,user--row-action--foo--confirmation-1
... (depends on row index) - for batch action, it will be
user--batch-action--foo--confirmation
New Contributors
Full Changelog: v0.25.7...v0.26.0
v0.25.8
v0.25.7
What's Changed
- Fix missing
theme
variable inblock
calls for proper theme inheritance by @Kreyu in #154 - Fix pagination per-page form not working properly with Turbo by @Kreyu in #155
- Remove default
ActionsColumnType
priority option value for better flexibility
Full Changelog: v0.25.6...v0.25.7
v0.25.6
v0.25.5
v0.25.4
What's changed
Fixed DateTimeColumnType
and DateColumnType
throwing exceptions during export due to incorrect formatter
option arguments
Full Changelog: v0.25.3...v0.25.4