### Start the development server Source: https://github.com/kreyu/data-table-bundle/blob/main/docs/README.md Run these commands in the terminal to install dependencies and launch the documentation development server. ```shell npm install && npm run docs:dev ``` -------------------------------- ### Rebuild assets Source: https://github.com/kreyu/data-table-bundle/blob/main/docs/src/docs/installation.md Install dependencies and start the watch process for asset compilation. ```shell yarn install --force && yarn watch ``` ```shell npm install --force && npm run watch ``` -------------------------------- ### Example HTML image tags Source: https://github.com/kreyu/data-table-bundle/blob/main/docs/src/reference/types/exporter/php-spreadsheet/html.md Comparison of default and custom image source paths. ```html ``` ```html ``` -------------------------------- ### Define filter default configuration Source: https://github.com/kreyu/data-table-bundle/blob/main/docs/src/reference/types/filter/options/filter.md Example of defining default filter settings within a Vue component setup script. ```javascript ``` -------------------------------- ### Configure ModalActionType with route Source: https://github.com/kreyu/data-table-bundle/blob/main/docs/src/reference/types/action/modal.md Examples of using the route option to define the modal content source, supporting both static and row-based dynamic route selection. ```php use Kreyu\Bundle\DataTableBundle\Action\Type\ModalActionType; $builder ->addAction('help', ModalActionType::class, [ 'route' => 'post_help_modal', ]) ; ``` ```php use Kreyu\Bundle\DataTableBundle\Action\Type\ModalActionType; $builder ->addRowAction('details', ModalActionType::class, [ 'route' => fn (Post $post) => $post->isPublished() ? 'post_published_details_modal' : 'post_draft_details_modal', ]) ; ``` -------------------------------- ### Configure ModalActionType with href Source: https://github.com/kreyu/data-table-bundle/blob/main/docs/src/reference/types/action/modal.md Examples of using the href option to define the modal content source, either as a static URL or dynamically per row. ```php use Kreyu\Bundle\DataTableBundle\Action\Type\ModalActionType; $builder ->addAction('help', ModalActionType::class, [ 'href' => $this->urlGenerator->generate('post_help_modal'); ]) ; ``` ```php use Kreyu\Bundle\DataTableBundle\Action\Type\ModalActionType; $builder ->addRowAction('details', ModalActionType::class, [ 'href' => fn (Post $post) => [ $this->urlGenerator->generate('post_details_modal', [ 'id' => $post->getId(), ]), ], ]) ; ``` -------------------------------- ### Configure Form HTTP Method Source: https://github.com/kreyu/data-table-bundle/blob/main/docs/src/reference/types/action/form.md Defines the HTTP method for the form submission, defaulting to GET. ```php use Kreyu\Bundle\DataTableBundle\Action\Type\FormActionType; $builder ->addAction('send', FormActionType::class, [ 'method' => 'POST', ]) ; ``` -------------------------------- ### Define Twig themes with hierarchy Source: https://github.com/kreyu/data-table-bundle/blob/main/docs/src/docs/features/theming.md Example of two separate Twig theme files where one overrides the other. ```twig {# themes/theme-a.html.twig #} {% block column_header %} {{ block('column_label') }} {% endblock %} {% block column_label %} Label A {% endblock %} ``` ```twig {# themes/theme-b.html.twig #} {% block column_label %} Label B {% endblock %} ``` -------------------------------- ### Define non-stringable entities Source: https://github.com/kreyu/data-table-bundle/blob/main/docs/src/docs/components/filters.md Example of Product and Category entities where the Category class does not implement a string representation. ```php readonly class Product { public function __construct( public Category $category, ) } readonly class Category { public function __construct( public string $name, ) } ``` -------------------------------- ### Configure pagination persistence globally Source: https://github.com/kreyu/data-table-bundle/blob/main/docs/src/docs/features/pagination.md Enable and configure pagination persistence settings globally using YAML or PHP configuration files. ```yaml kreyu_data_table: defaults: pagination: persistence_enabled: true # if persistence is enabled and symfony/cache is installed, null otherwise persistence_adapter: kreyu_data_table.sorting.persistence.adapter.cache # if persistence is enabled and symfony/security-bundle is installed, null otherwise persistence_subject_provider: kreyu_data_table.persistence.subject_provider.token_storage ``` ```php use Symfony\Config\KreyuDataTableConfig; return static function (KreyuDataTableConfig $config) { $defaults = $config->defaults(); $defaults->pagination() ->persistenceEnabled(true) // if persistence is enabled and symfony/cache is installed, null otherwise ->persistenceAdapter('kreyu_data_table.sorting.persistence.adapter.cache') // if persistence is enabled and symfony/security-bundle is installed, null otherwise ->persistenceSubjectProvider('kreyu_data_table.persistence.subject_provider.token_storage') ; }; ``` -------------------------------- ### FormActionType Hidden Inputs Source: https://github.com/kreyu/data-table-bundle/blob/main/docs/src/docs/components/actions.md Example of hidden inputs appended by scripts when using FormActionType. ```html ``` -------------------------------- ### Configure pagination globally Source: https://github.com/kreyu/data-table-bundle/blob/main/docs/src/docs/features/pagination.md Enable pagination globally using YAML or PHP configuration files. ```yaml kreyu_data_table: defaults: pagination: enabled: true ``` ```php use Symfony\Config\KreyuDataTableConfig; return static function (KreyuDataTableConfig $config) { $defaults = $config->defaults(); $defaults->pagination()->enabled(true); }; ``` -------------------------------- ### Define Book entity Source: https://github.com/kreyu/data-table-bundle/blob/main/docs/src/docs/components/filters.md Example entity structure for use with data table filters. ```php readonly class Book { public function __construct( public string $isbn, ) } ``` -------------------------------- ### Debug the cache adapter service Source: https://github.com/kreyu/data-table-bundle/blob/main/docs/src/docs/features/persistence.md Use the console to inspect the abstract cache adapter service definition. ```bash $ bin/console debug:container kreyu_data_table.persistence.adapter.cache ``` -------------------------------- ### Create a custom theme Source: https://github.com/kreyu/data-table-bundle/blob/main/docs/src/docs/features/theming.md Extend an existing theme or create a new one from scratch by defining blocks. ```twig {# themes/data_table.html.twig #} {% extends '@KreyuDataTable/themes/bootstrap_5.html.twig' %} {% block some_theme_block %} {# ... #} {% endblock %} ``` ```twig {% block some_theme_block %} {# ... #} {% endblock %} ``` -------------------------------- ### Configure Specific Persistence Adapter Source: https://github.com/kreyu/data-table-bundle/blob/main/docs/src/docs/features/persistence.md Create a concrete service definition inheriting from the abstract service, providing a unique prefix. ```yaml services: app.data_table.personalization.persistence.database: parent: app.data_table.persistence.database arguments: $prefix: personalization tags: - { name: kreyu_data_table.proxy_query.factory } ``` ```php use App\DataTable\Persistence\DatabasePersistenceAdapter; use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; return static function (ContainerConfigurator $configurator) { $configurator->services() ->set('app.data_table.personalization.persistence.database') ->parent('app.data_table.persistence.database') ->arg('$prefix', 'personalization') ; ``` -------------------------------- ### Configure Personalization Persistence Globally Source: https://github.com/kreyu/data-table-bundle/blob/main/docs/src/docs/features/personalization.md Enable and configure persistence settings for all data tables using the package configuration. ```yaml kreyu_data_table: defaults: personalization: persistence_enabled: true # if persistence is enabled and symfony/cache is installed, null otherwise persistence_adapter: kreyu_data_table.sorting.persistence.adapter.cache # if persistence is enabled and symfony/security-bundle is installed, null otherwise persistence_subject_provider: kreyu_data_table.persistence.subject_provider.token_storage ``` ```php use Symfony\Config\KreyuDataTableConfig; return static function (KreyuDataTableConfig $config) { $defaults = $config->defaults(); $defaults->personalization() ->persistenceEnabled(true) // if persistence is enabled and symfony/cache is installed, null otherwise ->persistenceAdapter('kreyu_data_table.sorting.persistence.adapter.cache') // if persistence is enabled and symfony/security-bundle is installed, null otherwise ->persistenceSubjectProvider('kreyu_data_table.persistence.subject_provider.token_storage') ; }; ``` -------------------------------- ### Defining Modal Row Action with Callable Options Source: https://github.com/kreyu/data-table-bundle/blob/main/docs/src/docs/components/actions.md Example of using the ModalActionType in a DataTable definition with a callable for template_vars. ```php class UserDataTableType extends AbstractDataTableType { public function buildDataTable(DataTableBuilderInterface $builder, array $options): void { $builder // ... ->addRowAction('details', ModalActionType::class, [ 'template_path' => 'user/details.html.twig', 'template_vars' => function (User $user) { // [!code ++] return [ // [!code ++] 'user_id' => $user->getId(), // [!code ++] ]; // [!code ++] }, // [!code ++] ]) ; } } ``` -------------------------------- ### Configure Data Table defaults in PHP Source: https://github.com/kreyu/data-table-bundle/blob/main/docs/src/reference/configuration.md Use this configuration file to set global defaults for the Kreyu Data Table bundle, including themes and persistence adapters. ```php defaults(); $defaults ->themes([ '@KreyuDataTable/themes/base.html.twig' ]) ->columnFactory('kreyu_data_table.column.factory') ->requestHandler('kreyu_data_table.request_handler.http_foundation') ; $defaults->sorting() ->enabled(true) ->persistenceEnabled(true) // if persistence is enabled and symfony/cache is installed, null otherwise ->persistenceAdapter('kreyu_data_table.sorting.persistence.adapter.cache') // if persistence is enabled and symfony/security-bundle is installed, null otherwise ->persistenceSubjectProvider('kreyu_data_table.persistence.subject_provider.token_storage') ; $defaults->pagination() ->enabled(true) ->persistenceEnabled(true) // if persistence is enabled and symfony/cache is installed, null otherwise ->persistenceAdapter('kreyu_data_table.pagination.persistence.adapter.cache') // if persistence is enabled and symfony/security-bundle is installed, null otherwise ->persistenceSubjectProvider('kreyu_data_table.persistence.subject_provider.token_storage') ->perPageChoices([10, 25, 50, 100]) ; $defaults->filtration() ->enabled(true) ->persistenceEnabled(true) // if persistence is enabled and symfony/cache is installed, null otherwise ->persistenceAdapter('kreyu_data_table.filtration.persistence.adapter.cache') // if persistence is enabled and symfony/security-bundle is installed, null otherwise ->persistenceSubjectProvider('kreyu_data_table.persistence.subject_provider.token_storage') ; $defaults->personalization() ->enabled(true) ->persistenceEnabled(true) // if persistence is enabled and symfony/cache is installed, null otherwise ->persistenceAdapter('kreyu_data_table.personalization.persistence.adapter.cache') // if persistence is enabled and symfony/security-bundle is installed, null otherwise ->persistenceSubjectProvider('kreyu_data_table.persistence.subject_provider.token_storage') ; $defaults->exporting() ->enabled(true) ->formFactory('form.factory') ->exporterFactory('kreyu_data_table.exporter.factory') ; }; ``` -------------------------------- ### Define a custom data object Source: https://github.com/kreyu/data-table-bundle/blob/main/docs/src/docs/components/columns.md Example of a simple readonly class representing the data structure for a custom column. ```php readonly class PhoneNumber { public function __construct( public string $nationalNumber, public string $countryCode, ) } ``` -------------------------------- ### Configure sorting persistence globally Source: https://github.com/kreyu/data-table-bundle/blob/main/docs/src/docs/features/sorting.md Enable and configure sorting persistence globally using YAML or PHP configuration files. ```yaml kreyu_data_table: defaults: sorting: persistence_enabled: true # if persistence is enabled and symfony/cache is installed, null otherwise persistence_adapter: kreyu_data_table.sorting.persistence.adapter.cache # if persistence is enabled and symfony/security-bundle is installed, null otherwise persistence_subject_provider: kreyu_data_table.persistence.subject_provider.token_storage ``` ```php use Symfony\Config\KreyuDataTableConfig; return static function (KreyuDataTableConfig $config) { $defaults = $config->defaults(); $defaults->sorting() ->persistenceEnabled(true) // if persistence is enabled and symfony/cache is installed, null otherwise ->persistenceAdapter('kreyu_data_table.sorting.persistence.adapter.cache') // if persistence is enabled and symfony/security-bundle is installed, null otherwise ->persistenceSubjectProvider('kreyu_data_table.persistence.subject_provider.token_storage') ; }; ``` -------------------------------- ### Download the bundle via Composer Source: https://github.com/kreyu/data-table-bundle/blob/main/docs/src/docs/installation.md Use this command to add the bundle dependency to your project. ```shell-vue composer require kreyu/data-table-bundle ``` -------------------------------- ### Multiple Checkbox Columns Hidden Inputs Source: https://github.com/kreyu/data-table-bundle/blob/main/docs/src/docs/components/actions.md Example of hidden inputs generated when using multiple checkbox columns with FormActionType. ```html ``` -------------------------------- ### Debug feature-specific cache adapters Source: https://github.com/kreyu/data-table-bundle/blob/main/docs/src/docs/features/persistence.md Inspect the specific cache adapter services created for pagination, sorting, filtration, and personalization. ```bash $ bin/console debug:container kreyu_data_table.pagination.persistence.adapter.cache $ bin/console debug:container kreyu_data_table.sorting.persistence.adapter.cache $ bin/console debug:container kreyu_data_table.filtration.persistence.adapter.cache $ bin/console debug:container kreyu_data_table.personalization.persistence.adapter.cache ``` -------------------------------- ### Configure sorting clearable behavior Source: https://github.com/kreyu/data-table-bundle/blob/main/docs/src/docs/features/sorting.md Examples for disabling the 'none' sorting state globally or for specific data table instances. ```yaml kreyu_data_table: defaults: sorting: clearable: false ``` ```php use Symfony\Config\KreyuDataTableConfig; return static function (KreyuDataTableConfig $config) { $defaults = $config->defaults(); $defaults->sorting()->clearable(false); }; ``` ```php use Kreyu\Bundle\DataTableBundle\Type\AbstractDataTableType; use Symfony\Component\OptionsResolver\OptionsResolver; class ProductDataTableType extends AbstractDataTableType { public function configureOptions(OptionsResolver $resolver): void { $resolver->setDefaults([ 'sorting_clearable' => false, ]); } } ``` ```php use App\DataTable\Type\ProductDataTableType; use Kreyu\Bundle\DataTableBundle\DataTableFactoryAwareTrait; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; class ProductController extends AbstractController { use DataTableFactoryAwareTrait; public function index() { $dataTable = $this->createDataTable( type: ProductDataTableType::class, query: $query, options: [ 'sorting_clearable' => false, ], ); } } ``` -------------------------------- ### Configure a filter with a custom option Source: https://github.com/kreyu/data-table-bundle/blob/main/docs/src/docs/integrations/doctrine-orm/expression-transformers.md Example of adding a custom 'unaccent' option to a filter within a DataTable type definition. ```php use Kreyuundle ablebundle ype abletype; use Kreyuundle ablebundle ablebuilderinterface; use Kreyuundle ablebundleridge able ilter ype iltertype; class producttabletype extends abstracttabletype { public function buildtable(tablebuilderinterface $builder, array $options): void { $builder ->addfilter('name', filtertype::class, [ 'unaccent' => true, ]) ; } } ``` -------------------------------- ### Implement a ProxyQueryFactory Source: https://github.com/kreyu/data-table-bundle/blob/main/docs/src/docs/features/extensibility.md Create a factory class implementing ProxyQueryFactoryInterface to handle raw data conversion. Throw UnexpectedTypeException if the data format is unsupported. ```php use App\DataTable\Query\ArrayProxyQuery; use Kreyu\Bundle\DataTableBundle\Query\ProxyQueryFactoryInterface; use Kreyu\Bundle\DataTableBundle\Query\ProxyQueryInterface; class ArrayProxyQueryFactory implements ProxyQueryFactoryInterface { public function create(mixed $data): ProxyQueryInterface { if (!is_array($data)) { throw new UnexpectedTypeException($data, ArrayProxyQuery::class); } return new ArrayProxyQuery($data); } } ``` -------------------------------- ### Configure ModalActionType with route_params Source: https://github.com/kreyu/data-table-bundle/blob/main/docs/src/reference/types/action/modal.md Examples of passing route parameters to the ModalActionType, including static arrays and dynamic closures for row data. ```php use Kreyu\Bundle\DataTableBundle\Action\Type\ModalActionType; $builder ->addAction('help', ModalActionType::class, [ 'route' => 'post_help_modal', 'route_params' => [ 'foo' => 'bar', ], ]) ; ``` ```php use Kreyu\Bundle\DataTableBundle\Action\Type\ModalActionType; $builder ->addRowAction('details', ModalActionType::class, [ 'route' => 'post_details_modal', 'route_params' => fn (Post $post) => [ 'id' => $post->getId(), ], ]) ; ``` -------------------------------- ### Configure themes globally Source: https://github.com/kreyu/data-table-bundle/blob/main/docs/src/docs/features/theming.md Set default themes for all data tables in the application using YAML or PHP configuration files. ```yaml # config/packages/kreyu_data_table.yaml kreyu_data_table: defaults: themes: - '@KreyuDataTable/themes/bootstrap_5.html.twig' - '@KreyuDataTable/themes/bootstrap_icons_ux.html.twig' - 'themes/data_table.html.twig' ``` ```php // config/packages/kreyu_data_table.php use Symfony\Config\KreyuDataTableConfig; return static function (KreyuDataTableConfig $config) { $config->defaults()->themes([ '@KreyuDataTable/themes/bootstrap_5.html.twig', '@KreyuDataTable/themes/bootstrap_icons_ux.html.twig', 'themes/data_table.html.twig', ]); }; ``` -------------------------------- ### Enable built-in transformers via filter options Source: https://github.com/kreyu/data-table-bundle/blob/main/docs/src/docs/integrations/doctrine-orm/expression-transformers.md Use the trim, lower, and upper options for a shorthand way to enable common built-in transformers. ```php use Kreyu\\\Bundle\\\DataTableBundle\\\Type\\\AbstractDataTableType; use Kreyu\\\Bundle\\\DataTableBundle\\\DataTableBuilderInterface; use Kreyu\\\Bundle\\\DataTableBundle\\\Bridge\\\Doctrine\\\Orm\\\Filter\\\Type\\\StringFilterType; class ProductDataTableType extends AbstractDataTableType { public function buildDataTable(DataTableBuilderInterface $builder, array $options): void { $builder ->addFilter('name', StringFilterType::class, [ 'trim' => true, 'lower' => true, 'upper' => true, ]) ; } } ``` -------------------------------- ### Implementing Variants in Custom Twig Themes Source: https://github.com/kreyu/data-table-bundle/blob/main/docs/src/docs/components/actions.md Example of how built-in themes map variant names to CSS classes within a Twig block. ```twig {% block action_button_control -%} {%- set variants = { destructive: 'btn-danger', danger: 'btn-danger', primary: 'btn-primary', }|merge(variants ?? {})|filter(e => e is not same as false) -%} {% set base_classes = base_classes ?? 'btn' %} {% set variant_classes = variant_classes ?? variants[variant ?? default_variant ?? 'primary'] %} {% set attr = attr|merge({ class: (base_classes ~ ' ' ~ variant_classes ~ ' ' ~ attr.class|default(''))|trim }) %} {# ... #} {%- block action_button_control %} ``` -------------------------------- ### Configuring Dropdown Caret Source: https://github.com/kreyu/data-table-bundle/blob/main/docs/src/reference/types/action/dropdown.md Demonstrates toggling the visibility of the caret icon in the dropdown label. ```php use Kreyu\Bundle\DataTableBundle\Action\Type\Dropdown\DropdownActionType; $builder ->addRowAction('dropdownWithCaret', DropdownActionType::class, [ 'label' => 'Dropdown with caret', 'with_caret' => true, 'actions' => [...], ]) ->addRowAction('dropdownWithoutCaret', DropdownActionType::class, [ 'label' => 'ยทยทยท', 'with_caret' => false, 'actions' => [...], ]) ; ``` -------------------------------- ### Configure Sorting Globally Source: https://github.com/kreyu/data-table-bundle/blob/main/docs/src/docs/features/sorting.md Enable sorting globally using YAML or PHP configuration files. ```yaml kreyu_data_table: defaults: sorting: enabled: true ``` ```php use Symfony\Config\KreyuDataTableConfig; return static function (KreyuDataTableConfig $config) { $defaults = $config->defaults(); $defaults->sorting()->enabled(true); }; ``` -------------------------------- ### Configure personalization settings Source: https://github.com/kreyu/data-table-bundle/blob/main/docs/src/docs/features/personalization.md Enable personalization globally via YAML or PHP configuration, or locally within a data table type or controller instance. ```yaml kreyu_data_table: defaults: personalization: enabled: true ``` ```php use Symfony\Config\KreyuDataTableConfig; return static function (KreyuDataTableConfig $config) { $defaults = $config->defaults(); $defaults->personalization()->enabled(true); }; ``` ```php use Kreyu\Bundle\DataTableBundle\Type\AbstractDataTableType; use Symfony\Component\OptionsResolver\OptionsResolver; class ProductDataTableType extends AbstractDataTableType { public function configureOptions(OptionsResolver $resolver): void { $resolver->setDefaults([ 'personalization_enabled' => true, ]); } } ``` ```php use App\DataTable\Type\ProductDataTableType; use Kreyu\Bundle\DataTableBundle\DataTableFactoryAwareTrait; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; class ProductController extends AbstractController { use DataTableFactoryAwareTrait; public function index() { $dataTable = $this->createDataTable( type: ProductDataTableType::class, query: $query, options: [ 'personalization_enabled' => true, ], ); } } ``` -------------------------------- ### Debug cache persistence clearer Source: https://github.com/kreyu/data-table-bundle/blob/main/docs/src/docs/features/persistence.md Use the console to inspect the built-in cache persistence clearer service. ```bash $ bin/console debug:container kreyu_data_table.persistence.clearer.cache ``` -------------------------------- ### Configure translation key and parameters Source: https://github.com/kreyu/data-table-bundle/blob/main/docs/src/docs/components/columns.md Use value_translation_key, value_translation_domain, and value_translation_parameters to map column values to translation keys. ```php use Kreyu\Bundle\DataTableBundle\Column\Type\TextColumnType; $builder->addColumn('months', TextColumnType::class, [ 'value_translation_key' => 'number_of_months', 'value_translation_domain' => 'product', 'value_translation_parameters' => fn (int $value) => [ 'months' => $value, ], ]); ``` -------------------------------- ### Configure filtration persistence globally Source: https://github.com/kreyu/data-table-bundle/blob/main/docs/src/docs/features/filtering.md Enable and configure persistence settings for all data tables using YAML or PHP configuration files. ```yaml kreyu_data_table: defaults: filtration: persistence_enabled: true # if persistence is enabled and symfony/cache is installed, null otherwise persistence_adapter: kreyu_data_table.filtration.persistence.adapter.cache # if persistence is enabled and symfony/security-bundle is installed, null otherwise persistence_subject_provider: kreyu_data_table.persistence.subject_provider.token_storage ``` ```php use Symfony\Config\KreyuDataTableConfig; return static function (KreyuDataTableConfig $config) { $defaults = $config->defaults(); $defaults->filtration() ->persistenceEnabled(true) // if persistence is enabled and symfony/cache is installed, null otherwise ->persistenceAdapter('kreyu_data_table.filtration.persistence.adapter.cache') // if persistence is enabled and symfony/security-bundle is installed, null otherwise ->persistenceSubjectProvider('kreyu_data_table.persistence.subject_provider.token_storage') ; }; ``` -------------------------------- ### Configure Exporting for Data Table Types and Instances Source: https://github.com/kreyu/data-table-bundle/blob/main/docs/src/docs/features/exporting.md Enable exporting for specific data table types or individual instances via options. ```php use Kreyu\Bundle\DataTableBundle\Type\AbstractDataTableType; use Symfony\Component\OptionsResolver\OptionsResolver; class ProductDataTableType extends AbstractDataTableType { public function configureOptions(OptionsResolver $resolver): void { $resolver->setDefaults([ 'exporting_enabled' => true, ]); } } ``` ```php use App\DataTable\Type\ProductDataTableType; use Kreyu\Bundle\DataTableBundle\DataTableFactoryAwareTrait; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; class ProductController extends AbstractController { use DataTableFactoryAwareTrait; public function index() { $dataTable = $this->createDataTable( type: ProductDataTableType::class, query: $query, options: [ 'exporting_enabled' => true, ], ); } } ``` -------------------------------- ### Enable personalization controller Source: https://github.com/kreyu/data-table-bundle/blob/main/docs/src/docs/features/personalization.md Add this configuration to assets/controllers.json to enable the personalization controller. ```json { "controllers": { "@kreyu/data-table-bundle": { "personalization": { "enabled": true } } } } ``` -------------------------------- ### Enable Action Confirmation Source: https://github.com/kreyu/data-table-bundle/blob/main/docs/src/docs/components/actions.md Set the confirmation option to true to require user interaction before executing an action. ```php $builder->addRowAction('remove', ButtonActionType::class, [ 'confirmation' => true, ]); ``` -------------------------------- ### Importing a Symfony UX Icon Source: https://github.com/kreyu/data-table-bundle/blob/main/docs/src/docs/features/theming.md Use the console command to import a specific icon when using UX icon themes. ```shell symfony console ux:icon:import bi:check ``` -------------------------------- ### Implement PersistenceAdapterInterface Source: https://github.com/kreyu/data-table-bundle/blob/main/docs/src/docs/features/persistence.md Create a class implementing the interface to define custom read and write logic for data persistence. ```php use Kreyuundle ablebundle esistence esistenceAdapterInterface; class DatabasePersistenceAdapter implements PersistenceAdapterInterface { public function __construct( private EntityManagerInterface $entityManager, private string $prefix, ) { } public function read(DataTableInterface $dataTable, PersistenceSubjectInterface $subject): mixed { // ... } public function write(DataTableInterface $dataTable, PersistenceSubjectInterface $subject, mixed $data): void { // ... } } ``` -------------------------------- ### Configure Stimulus controllers Source: https://github.com/kreyu/data-table-bundle/blob/main/docs/src/docs/installation.md Enable specific controllers in the assets/controllers.json file. ```json { "controllers": { "@kreyu/data-table-bundle": { "personalization": { "enabled": true }, "state": { "enabled": true }, "batch": { "enabled": true } } } } ``` -------------------------------- ### Register custom theme in bundle configuration Source: https://github.com/kreyu/data-table-bundle/blob/main/docs/src/docs/components/columns.md Add the custom theme file to the bundle configuration to make it available for rendering. ```yaml kreyu_data_table: defaults: themes: # ... - 'data_table/theme.html.twig' ``` ```php use Symfony\Config\KreyuDataTableConfig; return static function (KreyuDataTableConfig $config) { $config->defaults()->themes([ // ... 'data_table/theme.html.twig', ]); }; ``` -------------------------------- ### Implement PersistenceSubjectProviderInterface Source: https://github.com/kreyu/data-table-bundle/blob/main/docs/src/docs/features/persistence.md Create a class implementing the interface to define custom persistence logic. ```php use Kreyu\Bundle\DataTableBundle\Persistence\PersistenceSubjectProviderInterface; use Kreyu\Bundle\DataTableBundle\Persistence\PersistenceSubjectInterface; class CustomPersistenceSubjectProvider implements PersistenceSubjectProviderInterface { public function provide(): PersistenceSubjectInterface { // ... } } ``` -------------------------------- ### Configure HTML Separators and Export Options Source: https://github.com/kreyu/data-table-bundle/blob/main/docs/src/reference/types/column/collection.md Define a custom HTML separator for display and override it with a plain text separator for exports. ```php use Kreyuundle ablebundle ype abletype; $builder ->addColumn('tags', CollectionColumnType::class, [ 'separator' => '
', 'separator_html' => true, 'export' => [ 'separator' => ', ', 'separator_html' => false, // May not be needed at all. This depends on the exporter. ], ]) ; ``` -------------------------------- ### Configuring Action Icons Source: https://github.com/kreyu/data-table-bundle/blob/main/docs/src/reference/types/action/options/action.md Define icons for actions, supporting both static strings and dynamic closures for row-specific data. ```php use Kreyu\Bundle\DataTableBundle\Action\Type\ButtonActionType; $builder ->addAction('remove', ButtonActionType::class, [ 'icon' => 'trash', ]) ; ``` ```php use Kreyu\Bundle\DataTableBundle\Action\Type\ButtonActionType; $builder ->addRowAction('toggle', ButtonActionType::class, [ 'icon' => fn (User $user) => $user->isActive() ? 'unlock' : 'lock', ]) ; ``` -------------------------------- ### Create Data Table in Controller Source: https://github.com/kreyu/data-table-bundle/blob/main/docs/src/docs/usage.md Use the DataTableFactoryAwareTrait in a controller to instantiate a data table with a repository query builder. ```php use App\Repository\ProductRepository; use App\DataTable\Type\ProductDataTableType; use Kreyu\Bundle\DataTableBundle\DataTableFactoryAwareTrait; // [!code highlight] use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; class ProductController extends AbstractController { use DataTableFactoryAwareTrait; // [!code highlight] public function index(ProductRepository $productRepository) { $queryBuilder = $productRepository->createQueryBuilder('product'); $dataTable = $this->createDataTable(ProductDataTableType::class, $queryBuilder); } } ``` -------------------------------- ### Register the bundle in Symfony Source: https://github.com/kreyu/data-table-bundle/blob/main/docs/src/docs/installation.md Add the bundle class to the bundles configuration file to enable it. ```php return [ // ... Kreyu\Bundle\DataTableBundle\KreyuDataTableBundle::class => ['all' => true], ]; ``` -------------------------------- ### Pass options to the template view Source: https://github.com/kreyu/data-table-bundle/blob/main/docs/src/docs/components/columns.md Expose column options to the template by adding them to the view variables in buildValueView. ```php use Kreyu\Bundle\DataTableBundle\Column\Type\AbstractColumnType; use Kreyu\Bundle\DataTableBundle\Column\ColumnValueView; use Kreyu\Bundle\DataTableBundle\Column\ColumnInterface; class PhoneNumberColumnType extends AbstractColumnType { public function buildValueView(ColumnValueView $view, ColumnInterface $column, array $options): void { $view->vars['show_country_code'] = $options['show_country_code']; } } ``` -------------------------------- ### Implement a custom ProxyQuery Source: https://github.com/kreyu/data-table-bundle/blob/main/docs/src/docs/features/extensibility.md Create a class implementing ProxyQueryInterface to adapt custom data structures for the data table. ```php use Kreyuundle ablebundle Pagination PaginationData; use Kreyuundle ablebundle Sorting SortingData; use Kreyuundle ablebundle Query ProxyQueryInterface; use Kreyuundle ablebundle Query ResultSetInterface; class ArrayProxyQuery implements ProxyQueryInterface { public function __construct( private array $data, ) { } public function sort(SortingData $sortingData): void { } public function paginate(PaginationData $paginationData): void { } public function getResult(): ResultSetInterface { } } ``` -------------------------------- ### Configure currency with a callable Source: https://github.com/kreyu/data-table-bundle/blob/main/docs/src/reference/types/column/money.md Use a callable to dynamically determine the currency based on row data. ```php $builder ->addColumn('price', MoneyColumnType::class, [ 'currency' => fn (Product $product) => $product->getPriceCurrency(), ]) ; ``` -------------------------------- ### Configure global data table defaults in YAML Source: https://github.com/kreyu/data-table-bundle/blob/main/docs/src/reference/configuration.md Define default settings for themes, column factories, and persistence adapters across all data tables. ```yaml # config/packages/kreyu_data_table.yaml kreyu_data_table: defaults: themes: - '@KreyuDataTable/themes/base.html.twig' column_factory: kreyu_data_table.column.factory request_handler: kreyu_data_table.request_handler.http_foundation sorting: enabled: true persistence_enabled: false # if persistence is enabled and symfony/cache is installed, null otherwise persistence_adapter: kreyu_data_table.sorting.persistence.adapter.cache # if persistence is enabled and symfony/security-bundle is installed, null otherwise persistence_subject_provider: kreyu_data_table.persistence.subject_provider.token_storage pagination: enabled: true persistence_enabled: false # if persistence is enabled and symfony/cache is installed, null otherwise persistence_adapter: kreyu_data_table.pagination.persistence.adapter.cache # if persistence is enabled and symfony/security-bundle is installed, null otherwise persistence_subject_provider: kreyu_data_table.persistence.subject_provider.token_storage per_page_choices: [10, 25, 50, 100] filtration: enabled: true persistence_enabled: false # if persistence is enabled and symfony/cache is installed, null otherwise persistence_adapter: kreyu_data_table.filtration.persistence.adapter.cache # if persistence is enabled and symfony/security-bundle is installed, null otherwise persistence_subject_provider: kreyu_data_table.persistence.subject_provider.token_storage form_factory: form.factory filter_factory: kreyu_data_table.filter.factory personalization: enabled: false persistence_enabled: false # if persistence is enabled and symfony/cache is installed, null otherwise persistence_adapter: kreyu_data_table.personalization.persistence.adapter.cache # if persistence is enabled and symfony/security-bundle is installed, null otherwise persistence_subject_provider: kreyu_data_table.persistence.subject_provider.token_storage form_factory: form.factory exporting: enabled: true form_factory: form.factory exporter_factory: kreyu_data_table.exporter.factory ``` -------------------------------- ### Register Custom Provider as a Service Source: https://github.com/kreyu/data-table-bundle/blob/main/docs/src/docs/features/persistence.md Manually tag the service if autoconfiguration is not enabled. ```yaml services: app.data_table.persistence.subject_provider.custom: class: App\DataTable\Persistence\CustomPersistenceSubjectProvider tags: - { name: kreyu_data_table.persistence.subject_provider } ``` ```php use App\DataTable\Persistence\CustomPersistenceSubjectProvider; use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; return static function (ContainerConfigurator $configurator) { $configurator->services() ->set('app.data_table.persistence.database', CustomPersistenceSubjectProvider::class) ->tag('kreyu_data_table.persistence.subject_provider') ; } ``` -------------------------------- ### Add Stimulus dependency Source: https://github.com/kreyu/data-table-bundle/blob/main/docs/src/docs/installation.md Include the bundle's assets in your package.json file. ```json { "devDependencies": { "@kreyu/data-table-bundle": "file:vendor/kreyu/data-table-bundle/assets" } } ``` -------------------------------- ### Configure images_root option Source: https://github.com/kreyu/data-table-bundle/blob/main/docs/src/reference/types/exporter/php-spreadsheet/html.md Sets the base URL for images included in the exported HTML. ```php use Kreyu\Bundle\DataTableBundle\Bridge\PhpSpreadsheet\Exporter\Type\HtmlExporterType; $builder ->addExporter('html', HtmlExporterType::class, [ 'images_root' => 'https://www.domain.com', ]) ; ``` -------------------------------- ### Configure Exporting Globally Source: https://github.com/kreyu/data-table-bundle/blob/main/docs/src/docs/features/exporting.md Enable or disable the exporting feature globally using YAML or PHP configuration files. ```yaml kreyu_data_table: defaults: exporting: enabled: true ``` ```php use Symfony\Config\KreyuDataTableConfig; return static function (KreyuDataTableConfig $config) { $defaults = $config->defaults(); $defaults->exporting()->enabled(true); }; ``` -------------------------------- ### Register Abstract Persistence Service Source: https://github.com/kreyu/data-table-bundle/blob/main/docs/src/docs/features/persistence.md Define an abstract service in the container to serve as a base for specific persistence adapter implementations. ```yaml services: app.data_table.persistence.database: class: App\DataTable\Persistence\DatabasePersistenceAdapter abstract: true arguments: - '@doctrine.orm.entity_manager' ``` ```php use App\DataTable\Persistence\DatabasePersistenceAdapter; use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; return static function (ContainerConfigurator $configurator) { $configurator->services() ->set('app.data_table.persistence.database', DatabasePersistenceAdapter::class) ->args([service('doctrine.orm.entity_manager')]) ->abstract() ; ``` -------------------------------- ### Enable Batch Actions in controllers.json Source: https://github.com/kreyu/data-table-bundle/blob/main/docs/src/docs/components/actions.md Configuration required to enable the batch Stimulus controller for batch actions. ```json5 // assets/controllers.json { "controllers": { "@kreyu/data-table-bundle": { // ... "batch": { "enabled": true } } } } ``` -------------------------------- ### Define Action Type Options Source: https://github.com/kreyu/data-table-bundle/blob/main/docs/src/docs/components/actions.md Use the configureOptions method to define required options, defaults, and allowed types for a custom action type. ```php use Kreyuundle ablebundle ype ype ype; use Symfony\Component\OptionsResolver\OptionsResolver; class ModalActionType extends AbstractActionType { public function configureOptions(OptionsResolver $resolver): void { $resolver // define options required by the type ->setRequired('template_path') // define available options and their default values ->setDefaults([ 'template_vars' => [], ]) // optionally you can restrict type of the options ->setAllowedTypes('template_path', 'string') ->setAllowedTypes('template_vars', 'array') ; } } ``` -------------------------------- ### Configure per-page choices Source: https://github.com/kreyu/data-table-bundle/blob/main/docs/src/docs/features/pagination.md Configure the available options for the per-page select field globally, per data table type, or for a specific data table instance. ```yaml kreyu_data_table: defaults: pagination: per_page_choices: [10, 25, 50, 100] ``` ```php use Symfony\Config\KreyuDataTableConfig; return static function (KreyuDataTableConfig $config) { $defaults = $config->defaults(); $defaults->pagination() ->perPageChoices([10, 25, 50, 100) ; }; ``` ```php use Kreyu\Bundle\DataTableBundle\Type\AbstractDataTableType; use Symfony\Component\OptionsResolver\OptionsResolver; class ProductDataTableType extends AbstractDataTableType { public function configureOptions(OptionsResolver $resolver): void { $resolver->setDefaults([ 'per_page_choices' => [10, 25, 50, 100], ]); } } ``` ```php use App\DataTable\Type\ProductDataTableType; use Kreyu\Bundle\DataTableBundle\DataTableFactoryAwareTrait; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; class ProductController extends AbstractController { use DataTableFactoryAwareTrait; public function index() { $dataTable = $this->createDataTable( type: ProductDataTableType::class, query: $query, options: [ 'per_page_choices' => [10, 25, 50, 100], ], ); } } ``` -------------------------------- ### Generate a Data Table Class Source: https://github.com/kreyu/data-table-bundle/blob/main/src/Resources/help/MakeDataTable.txt Executes the command to create a new data table class by specifying the class name as an argument. ```bash php %command.full_name% ProjectDataTableType ``` -------------------------------- ### Use raw data without explicit ProxyQuery Source: https://github.com/kreyu/data-table-bundle/blob/main/docs/src/docs/features/extensibility.md Passing raw data directly requires a registered proxy query factory to avoid exceptions. ```php use App\DataTable\Type\ProductDataTableType; use Kreyu\Bundle\DataTableBundle\DataTableFactoryAwareTrait; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; class ProductController extends AbstractController { use DataTableFactoryAwareTrait; public function index() { // Note: products are just a simple array, ArrayProxyQuery is not required $products = [ new Product(name: 'Product #1'), new Product(name: 'Product #2'), new Product(name: 'Product #3'), ]; $dataTable = $this->createDataTable(ProductDataTableType::class, $products); } } ``` -------------------------------- ### ButtonActionType Configuration Source: https://github.com/kreyu/data-table-bundle/blob/main/docs/src/reference/types/action/button.md Configuring a button action with href and target attributes. ```APIDOC ## ButtonActionType Configuration ### Description The ButtonActionType is used to render an action as a button. It supports standard anchor attributes like href and target. ### Options - **href** (string|callable) - Optional - The URL for the action link. Defaults to '#'. - **target** (string|callable) - Optional - The target attribute for the link. Defaults to '_self'. ### Usage Example ```php use Kreyu\Bundle\DataTableBundle\Action\Type\ButtonActionType; $builder ->addAction('wiki', ButtonActionType::class, [ 'href' => 'https://example.com', 'target' => '_blank', ]); ``` ``` -------------------------------- ### Enable basic column sorting Source: https://github.com/kreyu/data-table-bundle/blob/main/docs/src/docs/features/sorting.md Set the sort option to true to enable sorting on a column using its name as the path. ```php use Kreyuundle ablebundle ablebuilderinterface; use Kreyuundle ablebundle ype umbercolumntype; use Kreyuundle ablebundle ype ype ype; class ProductDataTableType extends AbstractDataTableType { public function buildDataTable(DataTableBuilderInterface $builder, array $options): void { $builder ->addColumn('id', NumberColumnType::class, [ 'sort' => true, ]) ; } } ``` -------------------------------- ### Configure pagination for specific data table Source: https://github.com/kreyu/data-table-bundle/blob/main/docs/src/docs/features/pagination.md Enable pagination when creating a specific data table instance in a controller. ```php use App\DataTable\Type\ProductDataTableType; use Kreyu\Bundle\DataTableBundle\DataTableFactoryAwareTrait; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; class ProductController extends AbstractController { use DataTableFactoryAwareTrait; public function index() { $dataTable = $this->createDataTable( type: ProductDataTableType::class, query: $query, options: [ 'pagination_enabled' => true, ], ); } } ``` -------------------------------- ### Configure default personalization in DataTableType Source: https://github.com/kreyu/data-table-bundle/blob/main/docs/src/docs/features/personalization.md Demonstrates setting column priority, visibility, and personalizability using column options or the setDefaultPersonalizationData method. ```php use Kreyuundle ablebundle ablebuilderinterface; use Kreyuundle ablebundle ype abletype; use Kreyuundle ablebundle able abledata; use Kreyuundle ablebundle able ablecolumndata; class ProductDataTableType extends AbstractDataTableType { public function buildDataTable(DataTableBuilderInterface $builder, array $options): void { // using the columns options: $builder ->addColumn('id', NumberColumnType::class, [ 'priority' => -1, ]) ->addColumn('name', TextColumnType::class, [ 'visible' => false, ]) ->addColumn('createdAt', DateTimeColumnType::class, [ 'personalizable' => false, ]) ; // or using the data table builder's method: $builder->setDefaultPersonalizationData(new PersonalizationData([ new PersonalizationColumnData(name: 'id', priority: -1), new PersonalizationColumnData(name: 'name', visible: false), ])); // or by creating the personalization data from an array: $builder->setDefaultPersonalizationData(PersonalizationData::fromArray([ // each entry default values: name = from key, priority = 0, visible = false 'id' => ['priority' => -1], 'name' => ['visible' => false], ])); } } ``` -------------------------------- ### Define value translation parameters with a callable Source: https://github.com/kreyu/data-table-bundle/blob/main/docs/src/reference/types/column/options/column.md Shows how to use a callable to dynamically generate translation parameters based on the column value and row data. ```php // Assume the data table of User entities $builder->addColumn('firstName', options: [ 'value_translation_parameters' => function (string $firstName, User $user) { return [...]; }, ]); ``` -------------------------------- ### Configure Default Export Settings Source: https://github.com/kreyu/data-table-bundle/blob/main/docs/src/docs/features/exporting.md Use the setDefaultExportData method to define global export defaults like filename, exporter type, and strategy. ```php use Kreyu\Bundle\DataTableBundle\DataTableBuilderInterface; use Kreyu\Bundle\DataTableBundle\Exporter\ExportData; use Kreyu\Bundle\DataTableBundle\Type\AbstractDataTableType; class ProductDataTableType extends AbstractDataTableType { public function buildDataTable(DataTableBuilderInterface $builder, array $options): void { $builder ->setDefaultExportData(ExportData::fromArray([ 'filename' => sprintf('products_%s', date('Y-m-d')), 'exporter' => 'xlsx', 'strategy' => ExportStrategy::IncludeAll, 'include_personalization' => true, ])) ; } } ``` -------------------------------- ### Defining Dropdown Actions Source: https://github.com/kreyu/data-table-bundle/blob/main/docs/src/reference/types/action/dropdown.md Configures a dropdown action containing a link item using the builder. ```php use Kreyu\Bundle\DataTableBundle\Action\Type\Dropdown\DropdownActionType; use Kreyu\Bundle\DataTableBundle\Action\Type\Dropdown\LinkDropdownItemActionType; $builder ->addAction('advanced', DropdownActionType::class, [ 'actions' => [ $builder->createAction('update', LinkDropdownItemActionType::class, [ 'href' => '#' ]), ], ]) ; ``` -------------------------------- ### Implementing a Tooltip Action Type Extension Source: https://github.com/kreyu/data-table-bundle/blob/main/docs/src/docs/components/actions.md Extends the base action type to add Bootstrap tooltip attributes to button actions when a title is present. ```php use Kreyuundle ablebundle use Kreyuundle ablebundle use Symfony class TooltipActionTypeExtension extends AbstractActionTypeExtension { public function buildValueView(ActionValueView $view, ActionInterface $column, array $options): void { if (!$options['tooltip']) { return; } $title = $view->vars['attr']['title'] ?? null; if (empty($title)) { return; } $view->vars['attr']['data-bs-toggle'] = 'tooltip'; $view->vars['attr']['data-bs-placement'] = 'top'; $view->vars['attr']['data-bs-title'] = $title; } public function configureOptions(OptionsResolver $resolver): void { $resolver ->setDefault('tooltip', true) ->setAllowedTypes('tooltip', 'bool') ; } public static function getExtendedTypes(): iterable { return [ButtonActionType::class]; } } ``` -------------------------------- ### Configure themes for a data table type Source: https://github.com/kreyu/data-table-bundle/blob/main/docs/src/docs/features/theming.md Override global theme defaults within a specific data table type class by configuring the options resolver. ```php namespace App\DataTable\Type; use Kreyu\Bundle\DataTableBundle\AbstractDataTableType; use Symfony\Component\OptionsResolver\OptionsResolver; class ProductDataTableType extends AbstractDataTableType { public function configureOptions(OptionsResolver $resolver): void { $resolver->setDefault('themes', [ '@KreyuDataTable/themes/bootstrap_5.html.twig', '@KreyuDataTable/themes/bootstrap_icons_ux.html.twig', 'themes/data_table.html.twig', ]); } } ``` -------------------------------- ### Combining Variants with Custom Attributes Source: https://github.com/kreyu/data-table-bundle/blob/main/docs/src/docs/components/actions.md Demonstrates how to append custom CSS classes to an action that already has a defined variant. ```php use Kreyu\Bundle\DataTableBundle\Action\Type\FormActionType; $builder->addRowAction('delete', FormActionType::class, [ 'method' => 'DELETE', 'variant' => 'destructive', 'attr' => [ 'class' => 'px-3', // btn btn-danger [...] px-3 ], ]); ``` -------------------------------- ### Enable Column Exporting Source: https://github.com/kreyu/data-table-bundle/blob/main/docs/src/docs/features/exporting.md Set the 'export' option to true within the column configuration to include it in exported data. ```php use Kreyu\Bundle\DataTableBundle\DataTableBuilderInterface; use Kreyu\Bundle\DataTableBundle\Column\Type\NumberColumnType; use Kreyu\Bundle\DataTableBundle\Type\AbstractDataTableType; class ProductDataTableType extends AbstractDataTableType { public function buildDataTable(DataTableBuilderInterface $builder, array $options): void { $builder ->addColumn('id', NumberColumnType::class, [ 'export' => true, ]) ; } } ```