Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Datatables Bundle Laravel Package

uam/datatables-bundle

uam/datatables-bundle integrates jQuery DataTables into Symfony apps, adding server-side processing, Doctrine query support, and configurable column handling so you can build sortable, searchable, paginated tables with minimal boilerplate.

View on GitHub
Deep Wiki
Context7

Getting Started

Read this first: the package does not run on Laravel. uam/datatables-bundle is a Symfony 2 bundle (Symfony\Bundle\FrameworkBundle dependency, AppKernel registration, Assetic/Twig wiring). Its score, 4 stars and 0 dependents reflect that it is effectively unmaintained, and Symfony 2 reached end-of-life in November 2018. You cannot composer require it into a Laravel 9/10/11 app without dependency conflicts on symfony/framework-bundle and twig/twig.

So there are two realistic entry points:

  1. You inherited a Symfony 2 app that already uses it. Install with composer require uam/datatables-bundle, register new UAM\DatatablesBundle\UAMDatatablesBundle() in app/AppKernel.php, then php app/console assets:install --symlink so the bundled jQuery DataTables assets land in web/bundles/. Look first at Resources/views/ for the Twig table template and at the base DataTable class in the bundle root — that abstract class is the contract you extend.
  2. You are on Laravel and found this repo while researching. Skip the install. Use yajra/laravel-datatables for the actual work, and read this repo's DataTable abstraction only as a design reference for structuring column definitions and server-side response payloads. The DataTables jQuery plugin itself (the thing this bundle wraps) is framework-agnostic and will work fine behind a Laravel route returning JSON.

First use case, either way: render a table shell in a Blade/Twig view, point DataTables at a JSON endpoint, and have that endpoint translate draw/start/length/order/search query params into a paginated, ordered, filtered query.

Implementation Patterns

Subclass-per-table. The bundle's model is one class per table: extend the provided base class, declare columns and the data source (query builder or array), and let the bundle serialise the response. Mirror this in Laravel with a dedicated DataTable class per resource rather than stuffing logic into the controller — it keeps column definitions, searchable flags, and ordering whitelists in one auditable place.

Controller as a thin JSON endpoint. The controller should only resolve the DataTable service and return its response. Any business filtering (tenant scoping, soft-delete exclusion) belongs in the query builder passed to the DataTable, not in where clauses appended to the request after the fact.

Server-side vs client-side. Use client-side mode only for small, static datasets under a few thousand rows. For anything else, use server-side processing: it is the whole reason to have a backend bundle. Client-side mode on a large table will appear to work in dev and then destroy the browser in production.

Integration with an existing repository. Feed the DataTable a Doctrine QueryBuilder (Symfony) or Eloquent builder (Laravel port) and let the adapter apply orderBy/offset/limit. This composes cleanly with existing scopes and policies because you never bypass the ORM.

Response shape. Keep the DataTables contract exact: draw, recordsTotal, recordsFiltered, data. recordsTotal must be the unfiltered count and recordsFiltered the post-search count — swapping them is the single most common cause of "Showing 1 to 10 of 10 entries" while pagination clearly has more pages.

Auth before serialisation. Put the authorization check in the controller or a middleware/event listener, before the DataTable executes. Server-side processing is a full data-exfiltration surface if the endpoint is reachable without the same policy checks as the HTML page.

Gotchas and Tips

  • The draw counter must be echoed back verbatim. If you return a hardcoded value, DataTables will silently drop out-of-order responses and the table will flicker or stall under concurrent requests.
  • Never pass request-supplied column names into ORDER BY. Both this bundle's era and hand-rolled ports are vulnerable here. Map the incoming order[0][column] index to a fixed whitelist of column names you defined in the DataTable class; never interpolate the raw parameter.
  • CSRF on AJAX endpoints. Laravel's VerifyCsrfToken will reject the DataTables GET/POST unless you send the token header or exempt the route deliberately. Exempting blindly reintroduces the auth problem above.
  • Bundled asset versions drift. The jQuery DataTables JS/CSS shipped in Resources/public is pinned to whatever was current when the bundle was last touched. If your layout also loads DataTables from a CDN at a different major version, expect plugin API mismatches (fnServerData vs ajax, legacy Hungarian notation). Pick one source.
  • Assetic quirks. Asset publishing fails quietly if assets:install was run without --symlink on a case-insensitive filesystem, and the Twig template then renders an empty table with no console error beyond a 404 on the JS.
  • Counts are the performance bottleneck. recordsTotal runs a COUNT(*) on every keystroke-triggered request. Cache the unfiltered total per table (and invalidate on write) if the table is large; the filtered count must stay live.
  • Extension points are templates and services. Override the bundle's Twig template by placing an identically named file in app/Resources/UAMDatatablesBundle/views/, and replace the base class via a service definition override in services.yml. Both are unsupported-by-documentation but stable in practice.
  • Do not attempt a Laravel shim. Wrapping Symfony 2's DI container and Assetic inside Laravel costs more than rewriting the ~200 lines of query-to-JSON translation directly against yajra/laravel-datatables or even a hand-written controller.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
socialdept/atp-orm
cboxdk/laravel-assistant-client
socialdept/atp-resolver
socialdept/tenant-domains
tautvydasr/blade-class-names
socialdept/color-scales
maherelgamil/controller
coleus/widgets
coleus/table
coleus/users
coleus/music
coleus/health
coleus/calendar
coleus/notes
coleus/support
coleus/settings
coleus/apps
seampact/laravel
emmyconceptng/laravel-ng-postcode
jjsquady/round-robin