Recipe: Client-side Inline Data

What / When

Use inline data() when the full dataset is small and already available in the controller. DataTables handles search, sort, and paging in the browser.

Minimal Example

use Pentiminax\UX\DataTables\Column\NumberColumn;
use Pentiminax\UX\DataTables\Column\TextColumn;
use Pentiminax\UX\DataTables\Model\DataTableBuilderInterface;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;

final class ProductController extends AbstractController
{
    #[Route('/products', name: 'products')]
    public function index(DataTableBuilderInterface $builder): Response
    {
        $table = $builder
            ->createDataTable('products')
            ->columns([
                NumberColumn::new('id', 'ID'),
                TextColumn::new('name', 'Name'),
            ])
            ->data([
                ['id' => 1, 'name' => 'Keyboard'],
                ['id' => 2, 'name' => 'Mouse'],
            ])
            ->pageLength(10);

        return $this->render('product/index.html.twig', [
            'table' => $table,
        ]);
    }
}
{{ render_datatable(table) }}

Pitfalls