I use laravel livewire to produce the datatable However the pagination button didn't work
I tried 2 pagination method :
I already make sure these things :
Stack used :
My Livewire Class :
<?php
namespace App\Livewire\Users;
use App\Models\User;
use Livewire\Component;
use Livewire\WithPagination;
class Index extends Component
{
use WithPagination;
public function render()
{
return view('livewire.users.index', [
'users' => User::with(['sections','role'])->simplePaginate(2)
]);
}
}
the view :
<div class="relative sm:rounded-lg">
<table class="w-full text-sm text-left rtl:text-right text-gray-500 dark:text-gray-400">
<thead class="text-xs text-gray-700 uppercase bg-gray-50 dark:bg-gray-700 dark:text-gray-400">
...
</thead>
<tbody>
@foreach ($users as $user)
...
@endforeach
</tbody>
</table>
<div class="d-flex justify-content-between align-items-center my-4">
<div>
<label for="perPage">Tampilkan</label>
<select name="perPage" id="perPage" class="form-control" wire:model.live="perPage">
@foreach ($perPageOptions as $page)
<option value="{{ $page }}">{{ $page }}</option>
@endforeach
</select>
</div>
<div>
{{ $users->links() }}
</div>
</div>
</div>
livewire config :
return [
'pagination_theme' => 'tailwind',
];
tailwind config :
/** @type {import('tailwindcss').Config} */
export default {
content: [
"./resources/**/*.blade.php",
"./resources/**/*.js",
"./resources/**/*.vue",
"./node_modules/flowbite/**/*.js",
],
darkMode: "class",
theme: {
extend: {
colors: {
primary: {
50: "#eff6ff",
100: "#dbeafe",
200: "#bfdbfe",
300: "#93c5fd",
400: "#60a5fa",
500: "#3b82f6",
600: "#2563eb",
700: "#1d4ed8",
800: "#1e40af",
900: "#1e3a8a",
950: "#172554",
},
},
},
fontFamily: {
body: [
"Inter",
"ui-sans-serif",
"system-ui",
"-apple-system",
"system-ui",
"Segoe UI",
"Roboto",
"Helvetica Neue",
"Arial",
"Noto Sans",
"sans-serif",
"Apple Color Emoji",
"Segoe UI Emoji",
"Segoe UI Symbol",
"Noto Color Emoji",
],
sans: [
"Inter",
"ui-sans-serif",
"system-ui",
"-apple-system",
"system-ui",
"Segoe UI",
"Roboto",
"Helvetica Neue",
"Arial",
"Noto Sans",
"sans-serif",
"Apple Color Emoji",
"Segoe UI Emoji",
"Segoe UI Symbol",
"Noto Color Emoji",
],
},
},
plugins: [require("flowbite/plugin")],
};
How to solve this ?
You're missing the pagination views in your tailwind's content
config. You should add it to prevent the relevant CSS classes from being purged.
It should look like this:
content: [
'./resources/**/*.blade.php',
'./resources/**/*.js',
'./resources/**/*.vue',
'./vendor/laravel/framework/src/Illuminate/Pagination/resources/views/*.blade.php',
],
See Laravel's documentation on pagination for more info: https://laravel.com/docs/11.x/pagination#tailwind-jit