Skip to content

Configuration

Configuration

Configure bundle-wide defaults in config/packages/datatables.yaml.

Full Configuration Reference

data_tables:
options:
language: en-GB
layout:
topStart: pageLength
topEnd: search
bottomStart: info
bottomEnd: paging
lengthMenu: [10, 25, 50]
pageLength: 10
template_parameters:
class: 'table'
extensions:
buttons: [csv, excel, pdf, print]
select:
style: single

Options

language

Sets the default language locale for DataTables UI elements. The bundle translates locale codes into the correct CDN URL for DataTables language files.

data_tables:
options:
language: fr-FR # French
# language: de-DE # German
# language: es-ES # Spanish

Supported locales: Any locale supported by DataTables i18n.

layout

Controls the positioning of DataTables UI features. Each position accepts a feature name.

data_tables:
options:
layout:
topStart: pageLength # Page length selector
topEnd: search # Search box
bottomStart: info # "Showing X of Y entries"
bottomEnd: paging # Pagination controls

Available positions: topStart, topEnd, bottomStart, bottomEnd, top, bottom

Available features: pageLength, search, info, paging, buttons

lengthMenu

Defines the available page length options shown in the dropdown:

data_tables:
options:
lengthMenu: [10, 25, 50, 100]

You can also provide custom labels:

// In PHP
$table->lengthMenu([
[10, 25, 50, -1],
[10, 25, 50, 'All']
]);

pageLength

Sets the initial number of rows displayed:

data_tables:
options:
pageLength: 25

Template Parameters

Default HTML attributes for the generated <table> element:

data_tables:
template_parameters:
class: 'table table-striped table-hover'
id: 'my-default-table'

These can be overridden per-table in Twig:

{{ render_datatable(table, {'class': 'custom-class'}) }}

Extensions

Configure default extensions enabled for all tables:

data_tables:
extensions:
buttons: [csv, excel, pdf, print, copy, colvis]
select:
style: single # or 'multi'

Buttons Extension

extensions:
buttons:
- csv
- excel
- pdf
- print
- copy
- colvis # Column visibility toggle

Select Extension

extensions:
select:
style: single # Single row selection
# style: multi # Multiple row selection

Per-Table Override

Bundle defaults can be overridden for individual tables:

$table = $builder
->createDataTable('myTable')
->pageLength(50) // Override default 10
->language(Language::DE) // Override default en-GB
->columns([/* ... */]);

Environment-Specific Configuration

Use Symfony’s configuration system for different environments:

# config/packages/datatables.yaml (default)
data_tables:
options:
pageLength: 10
# config/packages/dev/datatables.yaml
data_tables:
options:
pageLength: 5 # Smaller for development