DataTable
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
| Method | Description |
| `add(ColumnInterface $column)` | Add a single column |
| `columns(array|ColumnInterface $columns)` | Set multiple columns |
| `getColumns(): array` | Return all configured columns |
| `getColumnByName(string $name): ?ColumnInterface` | Find a column by its name |
Data Loading
| Method | Description |
| `ajax(string $url, ?string $dataSrc = null, string $type = 'GET')` | Configure Ajax endpoint and request mode |
| `data(array $data)` | Provide inline client-side data |
| `serverSide(bool $serverSide = true)` | Enable server-side processing mode |
| `apiPlatform(bool $enabled = true)` | Enable API Platform adapter behavior |
| `mercure(string $hubUrl, array $topics = [], bool $withCredentials = false, ?int $debounceMs = null)` | Enable Mercure live updates with one or many topics |
Feature Control
| Method | Description |
| `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 |
Layout And Paging
| Method | Description |
| `layout(Feature $topStart, Feature $topEnd, Feature $bottomStart, Feature $bottomEnd)` | Position DataTables UI blocks |
| `displayStart(int $displayStart)` | Set initial row offset |
| `lengthMenu(array $lengthMenu)` | Configure available page sizes |
| `pageLength(int $pageLength)` | Set default page size |
| Method | Description |
| `scrollX(bool $scrollX)` | Enable horizontal scrolling |
| `scrollY(string $scrollY)` | Set vertical scroll height |
Internationalization
| Method | Description |
| `language(Language $language)` | Set UI language |
| `search(string $search)` | Set initial search value |
| `withSearchOption(SearchOption $searchOption)` | Set full search option object |
Extensions
| Method | Description |
| `addExtension(ExtensionInterface $extension)` | Add one extension |
| `extensions(array $extensions)` | Set multiple extensions |
| `getExtensions(): array` | Return configured extensions |
| `setExtensions(DataTableExtensions $extensions)` | Replace extension collection |
| `responsive()`, `columnControl()` | Convenience helpers for common extensions |
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,
);
Cross Links