TextColumn
Render plain text or HTML string values in table cells
TextColumn is the default column type for string values. It uses the DataTables string type for sorting and searching, which means values are compared as plain text. Display is HTML-escaped, so characters like < show as text instead of markup.
Basic Usage
use Pentiminax\UX\DataTables\Column\TextColumn;
TextColumn::new('name', 'Name');
HTML Content
When the cell value contains trusted HTML markup, call html() to switch the DataTables type to html. Display then inserts the markup as HTML. Sorting and searching strip tags, so users search against the visible text, not the markup. Do not call html() on user-controlled values unless they are already sanitized.
TextColumn::new('description', 'Description')
->html();
UTF-8 Sorting
For non-ASCII text (accented characters, CJK), use utf8() to switch to a UTF-8 aware comparison algorithm:
TextColumn::new('name', 'Name')
->utf8();
Combining both uses the html-utf8 type:
TextColumn::new('content', 'Content')
->html()
->utf8();
API Reference
| Method | Description |
|---|---|
TextColumn::new(string $name, string $title = '') | Creates a new TextColumn (type: string) |
html(bool $html = true) | Renders the cell as HTML (or html-utf8 with utf8()). Skip this on unsanitized user input. |
utf8(bool $utf8 = true) | Switches to string-utf8 type (or html-utf8 when combined with html()) |
Complete Example
use Pentiminax\UX\DataTables\Attribute\AsDataTable;
use Pentiminax\UX\DataTables\Column\NumberColumn;
use Pentiminax\UX\DataTables\Column\TextColumn;
use Pentiminax\UX\DataTables\Model\AbstractDataTable;
#[AsDataTable(User::class)]
final class UsersDataTable extends AbstractDataTable
{
public function configureColumns(): iterable
{
yield NumberColumn::new('id', 'ID')->setWidth('60px');
yield TextColumn::new('name', 'Name')->utf8();
yield TextColumn::new('bio', 'Bio')->html()->utf8();
}
protected function mapRow(mixed $row): array
{
return [
'id' => $row->getId(),
'name' => $row->getName(),
'bio' => $row->getBio(),
];
}
}