user pagination

This commit is contained in:
Saufi
2026-05-11 12:20:39 +08:00
parent a461f0bb42
commit 3e79e74cb7
5 changed files with 95 additions and 35 deletions

View File

@@ -0,0 +1,34 @@
<table class="w-full text-sm text-left text-gray-900 dark:text-gray-100">
<thead class="text-xs text-gray-700 dark:text-gray-400 uppercase bg-gray-50 dark:bg-gray-700">
<tr>
<th class="px-6 py-3">#</th>
<th class="px-6 py-3">{{ __('Name') }}</th>
<th class="px-6 py-3">{{ __('Email') }}</th>
<th class="px-6 py-3">{{ __('Joined') }}</th>
</tr>
</thead>
<tbody>
@foreach ($users as $user)
<tr class="{{ $loop->even ? 'bg-gray-50 dark:bg-gray-700' : 'bg-white dark:bg-gray-800' }} border-b border-gray-200 dark:border-gray-600">
<td class="px-6 py-4">{{ $users->firstItem() + $loop->index }}</td>
<td class="px-6 py-4 font-medium">{{ $user->name }}</td>
<td class="px-6 py-4">{{ $user->email }}</td>
<td class="px-6 py-4">{{ $user->created_at->format('d M Y') }}</td>
</tr>
@endforeach
@if ($users->isEmpty())
<tr>
<td colspan="4" class="px-6 py-4 text-center text-gray-500 dark:text-gray-400">
{{ __('No users found.') }}
</td>
</tr>
@endif
</tbody>
</table>
@if ($users->hasPages())
<div class="mt-4">
{{ $users->links() }}
</div>
@endif

View File

@@ -8,35 +8,33 @@
<div class="py-12">
<div class="max-w-7xl mx-auto sm:px-6 lg:px-8">
<div class="bg-white dark:bg-gray-800 overflow-hidden shadow-sm sm:rounded-lg">
<div class="p-6">
<table class="w-full text-sm text-left text-gray-900 dark:text-gray-100">
<thead class="text-xs text-gray-700 dark:text-gray-400 uppercase bg-gray-50 dark:bg-gray-700">
<tr>
<th class="px-6 py-3">#</th>
<th class="px-6 py-3">{{ __('Name') }}</th>
<th class="px-6 py-3">{{ __('Email') }}</th>
<th class="px-6 py-3">{{ __('Joined') }}</th>
</tr>
</thead>
<tbody>
@foreach ($users as $index => $user)
<tr class="{{ $index % 2 === 0 ? 'bg-white dark:bg-gray-800' : 'bg-gray-50 dark:bg-gray-700' }} border-b border-gray-200 dark:border-gray-600">
<td class="px-6 py-4">{{ $index + 1 }}</td>
<td class="px-6 py-4 font-medium">{{ $user->name }}</td>
<td class="px-6 py-4">{{ $user->email }}</td>
<td class="px-6 py-4">{{ $user->created_at->format('d M Y') }}</td>
</tr>
@endforeach
<div
class="p-6"
x-data="{
loading: false,
async paginate(url) {
this.loading = true;
const response = await fetch(url, {
headers: { 'X-Requested-With': 'XMLHttpRequest' }
});
this.$refs.tableContainer.innerHTML = await response.text();
this.loading = false;
}
}"
@click.prevent="
const link = $event.target.closest('a[href]');
if (link && $refs.tableContainer.contains(link)) {
paginate(link.href);
}
"
>
<div x-show="loading" class="text-center py-4 text-gray-500 dark:text-gray-400">
{{ __('Loading...') }}
</div>
@if ($users->isEmpty())
<tr>
<td colspan="4" class="px-6 py-4 text-center text-gray-500 dark:text-gray-400">
{{ __('No users found.') }}
</td>
</tr>
@endif
</tbody>
</table>
<div x-ref="tableContainer" x-show="!loading">
@include('users._table')
</div>
</div>
</div>
</div>