Type to search columns, filters, options, and extensions.

↑↓ to navigate · Enter to open · Esc to close

Documentation

DataTable

Reference for the DataTable fluent configuration API

DataTable is the fluent API used to configure table options, columns, extensions, and loading mode.

Constructor

new DataTable(
    id: 'users',
    options: [],
    attributes: [],
    extensions: [],
)

Core Methods

Columns

MethodDescription
add(ColumnInterface $column)Add a single column
columns(array $columns)Replace the column list with the given array
getColumns(): ColumnInterface[]Return configured column objects keyed by name
getColumnDefinitions(): arrayReturn the serialized DataTables column definitions
getColumnByName(string $name): ?ColumnInterfaceFind a column by its name

Client-side Processing And Data Sources

MethodDescription
ajax(string $url, ?string $dataSrc = null, string $type = 'GET')Configure Ajax endpoint and request mode
ajaxRequestData(string $url, array $data, string $type = 'GET')Configure Ajax endpoint with extra request data sent on every call
mergeAjaxData(array $data)Merge additional key/value pairs into Ajax request data
data(array $data)Provide inline client-side data
forwardQueryParameters(array $parameters)Capture the named page query parameters at render time and forward them on every Ajax call
urlState(array $keys = [], string $prefix = '')Sync selected DataTables state keys to the page URL query string
serverSide(bool $serverSide = true)Enable server-side processing mode
apiPlatform(bool $enabled = true)Opt-in to API Platform integration: column auto-detection and collection URL resolution
mercure(array $topics = [], bool $withCredentials = false, ?int $debounceMs = null)Enable Mercure live updates with one or many topics
poll(string|int $interval)Reload the Ajax source every N seconds (30, '10s', '1m'); minimum 2 seconds

Feature Control

MethodDescription
autoWidth(bool $autoWidth)Toggle automatic width calculation
deferRender(bool $deferRender)Delay rendering of non-visible rows
info(bool $info)Show/hide table info summary
lengthChange(bool $lengthChange)Enable/disable page-size selector
ordering(bool $handler = true, bool $indicators = true)Configure column ordering behavior
withoutOrdering()Disable ordering
paging(...)Configure pagination behavior
withoutPaging()Disable pagination
processing(bool $processing = true)Toggle processing indicator
searching(bool $searching = true)Toggle global search
stateSave(bool $stateSave = true)Persist table state in browser
setPermission(string|Expression $attribute)Restrict table rendering and bundle Ajax access with a Symfony security attribute or expression

Layout And Paging

MethodDescription
layout(array $layout)Position DataTables UI blocks
caption(string $caption)Set the table caption text
displayStart(int $displayStart)Set initial row offset
lengthMenu(array $lengthMenu)Configure available page sizes
pageLength(int $pageLength)Set default page size

Empty State And Row Presentation

MethodDescription
emptyState(string $heading, ?string $description = null, ?Icon $icon = null, ?array $action = null)Replace the empty-table message with a heading, description, icon, and an optional ['label' => ..., 'url' => ...] action. The URL must be a path starting with / or an http(s) URL, otherwise an InvalidArgumentException is thrown
rowClass(callable $resolver)CSS classes for each row, resolved from the source row (callable(mixed): ?string) and emitted as DT_RowClass
recordUrl(callable $resolver)URL each row navigates to when clicked, resolved from the source row (callable(mixed): ?string). Only a path starting with / or an http(s) URL is kept
use Pentiminax\UX\DataTables\Enum\Icon;
use Pentiminax\UX\DataTables\Model\DataTable;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;

$table = (new DataTable('orders'))
    ->emptyState('No orders yet', 'Orders appear here once customers check out.', Icon::Inbox, [
        'label' => 'Create an order',
        'url'   => '/orders/new',
    ])
    ->rowClass(static fn (Order $order): ?string => $order->isOverdue() ? 'table-danger' : null)
    ->recordUrl(fn (Order $order): string => $this->urlGenerator->generate('order_show', ['id' => $order->getId()]));

See Row Presentation for behavior, accessibility, and security notes.

Edit Modal

MethodDescription
editModalTemplate(string $template)Twig template used for the inline edit modal
editModalAdapter(string $adapter)Modal adapter name (dt, bs, bs4, bs5, or a name registered with modalAdapters.register())

Scrolling

MethodDescription
scrollX(bool $scrollX)Enable horizontal scrolling
scrollY(string $scrollY)Set vertical scroll height

Internationalization

MethodDescription
language(Language $language)Set UI language
search(string $search)Set initial search value
withSearchOption(SearchOption $searchOption)Set full search option object

Styling

MethodDescription
styleFramework(StyleFramework $framework)Declare the CSS framework, skipping frontend autodetection

Extensions

MethodDescription
addExtension(ExtensionInterface $extension)Add one extension
extensions(array $extensions)Set multiple extensions
getExtensions(): arrayReturn configured extensions
setExtensions(DataTableExtensions $extensions)Replace extension collection
responsive(bool $auto = true, ?array $breakpoints = null, int|string $detailsTarget = 0, string|false $detailsType = 'inline', string $orthogonal = 'display')Add the Responsive extension
columnControl(int|string|null $target = null, ?array $content = null)Add Column Control; a target replaces the defaults with that single control group
select(SelectStyle $style = SelectStyle::SINGLE, ..., bool $withCheckbox = false, bool $headerCheckbox = false)Add the Select extension, checkbox column included
keyTable(bool $blurable = true, ...)Add the KeyTable extension
scroller(float $boundaryScale = 0.5, ...)Add the Scroller extension; pair it with scrollY()
colReorder(bool $enable = true, ...)Add the ColReorder extension
searchBuilder(string|array $columns = '*', ...)Add the SearchBuilder extension and its layout slot
fixedColumns(int $start = 1, int $end = 0)Add the FixedColumns extension
fixedHeader(bool $header = true, bool $footer = false, ...)Add the FixedHeader extension
rowGroup(int|string|array $dataSrc, ...)Add the RowGroup extension; the grouping data source is required

Public API

The methods documented here are the supported configuration surface. A few public methods exist only because the runtime calls them while preparing a render, such as setPreparedFilterLabels(), markTemplateColumnsRendered(), or setDataTableClass(). They carry an @internal tag in their PHPDoc and are excluded from the backward-compatibility promise: do not call them from your tables, because they can change or move in any release.

Example

use Pentiminax\UX\DataTables\Enum\Feature;
use Pentiminax\UX\DataTables\Enum\Language;
use Pentiminax\UX\DataTables\Model\DataTable;

$table = (new DataTable('users'))
    ->serverSide(true)
    ->processing(true)
    ->language(Language::EN)
    ->layout([
        'topStart'    => Feature::PAGE_LENGTH,
        'topEnd'      => Feature::SEARCH,
        'bottomStart' => Feature::INFO,
        'bottomEnd'   => Feature::PAGING,
    ]);