A dynamic DataTables plugin for Laravel using Tailwind CSS and Alpine.js. This package provides an easy way to create responsive, searchable, and sortable tables in your Laravel application.
composer require shenryuken/laravel-datatables
php artisan vendor:publish --tag=laravel-datatables
Run `npm run dev` to compile your assets.
resources/js/app.js
file, import Alpine and the DataTable functionality:import './bootstrap';
import Alpine from 'alpinejs';
import './vendor/laravel-datatables/data-table';
window.Alpine = Alpine;
Alpine.start();
npm run dev
to compile your assets.To use the DataTable in your Blade views:
<x-laravel-datatables::data-table
id="users-table"
:columns="[
['field' => 'id', 'label' => 'ID'],
['field' => 'name', 'label' => 'Name'],
['field' => 'email', 'label' => 'Email'],
['field' => 'created_at', 'label' => 'Created At'],
]"
url="{{ route('datatable.getData', ['table' => 'users']) }}"
/>
Make sure to include Tailwind CSS in your project for proper styling.
You can customize the DataTable component by publishing the views and modifying them:
php artisan vendor:publish --tag=laravel-datatables --force
This will publish the component views to resources/views/vendor/laravel-datatables
.
This package is open-sourced software licensed under the MIT license.