- How do I install yajra/laravel-datatables in Laravel 13?
- Run `composer require yajra/laravel-datatables:^13` to install the package. Laravel 13+ auto-discovers the service provider, so no manual registration is needed in `config/app.php`. The package bundles DataTables 2.x core and plugins (Buttons, Select, Editor) for immediate use.
- Does this package support DataTables Editor 2.x for inline CRUD operations?
- Yes, the package includes optional integration for DataTables Editor 2.x. After installing, configure the Editor extension in your JavaScript and use `DataTables::of()->editColumn()` to define editable fields. The backend handles server-side validation and updates via Laravel’s Eloquent or Query Builder.
- Can I use this with Livewire or Inertia.js instead of Blade?
- Absolutely. The package exposes RESTful JSON endpoints, so you can consume them in Livewire (via `$this->emit()` or properties) or Inertia.js (by fetching the endpoint directly). The frontend dependency (DataTables 2.x) remains the same, but the backend logic is framework-agnostic.
- What Laravel versions does yajra/laravel-datatables support?
- The package follows Laravel’s versioning strictly: `^13` is for Laravel 13.x only. For Laravel 11/12, use `^11` or `^12` respectively. Check the [compatibility table](https://github.com/yajra/datatables#laravel-version-compatibility) to avoid breaking changes during upgrades.
- How do I optimize performance for large datasets (e.g., 100K+ rows)?
- Server-side processing handles pagination/sorting/filtering efficiently, but optimize queries with indexing, `select()` clauses, and Eloquent scopes. For extreme cases, cache query results using Laravel’s cache drivers (e.g., `DataTables::of()->cache(60)`). Avoid `SELECT *` and use database-level optimizations like composite indexes.
- Is there a way to customize the JSON response structure before sending it to DataTables?
- Yes, use the `preQuery` and `postProcess` hooks in the `DataTables` facade. For example, `DataTables::of($query)->preQuery(function($query) { ... })` modifies the query, while `postProcess` lets you alter the final JSON array. Hooks are documented in the [Laravel DataTables API](http://yajrabox.com/docs/laravel-datatables).
- Can I use this package with PostgreSQL or SQLite instead of MySQL?
- Yes, the package is database-agnostic and works with PostgreSQL, SQLite, and others via Laravel’s Query Builder. No additional configuration is needed—server-side processing adapts to your database schema. Test edge cases like JSON columns or custom data types in your queries.
- What are the risks of migrating from a custom DataTables implementation to this package?
- The main risks are frontend dependency changes (DataTables 2.x) and backend logic adjustments if you relied on custom server-side processing. Audit your existing code for hardcoded queries or non-standard JSON responses. The package’s `DataTables::of()` method provides flexibility to replicate old behavior.
- How do I add bulk actions (e.g., delete selected rows) using the Buttons extension?
- Configure the Buttons extension in your DataTables initialization with `buttons: ['deleteSelected']`. On the backend, capture the selected IDs via `DataTables::of()->getSelected()` and process them in a controller. Example: `DataTables::of(User::query())->buttons(['deleteSelected'])->editColumn('action', '...');`
- Does this package work with Laravel’s first-party testing tools (Pest or PHPUnit)?
- Yes, test server-side logic by mocking the `DataTables` facade. For example, in PHPUnit: `$this->partialMock(DataTables::class, ['of'])->expects($this->once())->method('of')->willReturnSelf();`. Test JSON responses with `assertJson()` and validate pagination/sorting behavior. Frontend tests require DataTables 2.x in your test environment.