fix: resolve client-side table search limitation across all 7 paginated views with global server search and per-page selector
This commit is contained in:
@@ -71,7 +71,7 @@
|
||||
</div>
|
||||
|
||||
<!-- Kotak Pencarian & Filter Status Simper (Tanpa Card Wrapper, Format Referensi) -->
|
||||
<form method="GET" action="{{ route('hse.employees.index') }}" class="flex flex-col sm:flex-row items-stretch sm:items-center justify-between gap-2.5 sm:gap-3">
|
||||
<form method="GET" action="{{ route('hse.employees.index') }}" id="employeeFilterForm" class="flex flex-col sm:flex-row items-stretch sm:items-center justify-between gap-2.5 sm:gap-3">
|
||||
<!-- Pencarian Cepat di Kiri -->
|
||||
<div class="relative w-full sm:max-w-md">
|
||||
<span class="absolute inset-y-0 left-0 pl-3.5 flex items-center pointer-events-none text-slate-400">
|
||||
@@ -85,7 +85,7 @@
|
||||
class="w-full text-xs pl-10 pr-4 py-2.5 rounded-xl border border-slate-200 bg-white text-slate-800 placeholder-slate-400 focus:outline-none focus:border-[#1b5e20] focus:ring-2 focus:ring-[#1b5e20]/10 shadow-sm transition">
|
||||
</div>
|
||||
|
||||
<!-- Filter di Kanan (Pada Mobile: Sejajar 2 Kolom di Bawah Search Bar) -->
|
||||
<!-- Filter di Kanan (Pada Mobile: Sejajar di Bawah Search Bar) -->
|
||||
<div class="flex flex-col sm:flex-row items-stretch sm:items-center justify-end gap-2 sm:gap-2.5 w-full sm:w-auto">
|
||||
<div class="grid grid-cols-2 gap-2 sm:flex sm:items-center sm:gap-2.5 w-full sm:w-auto">
|
||||
<!-- Filter Jenis Personil / Karyawan -->
|
||||
@@ -118,11 +118,25 @@
|
||||
<option value="expiring_soon" {{ request('simper_status') === 'expiring_soon' ? 'selected' : '' }}>Segera Habis (≤ 30 Hari)</option>
|
||||
<option value="expired" {{ request('simper_status') === 'expired' ? 'selected' : '' }}>Kedaluwarsa (Expired)</option>
|
||||
</select>
|
||||
|
||||
<!-- Filter Tampilan Per Halaman -->
|
||||
<select name="per_page"
|
||||
onchange="this.form.submit()"
|
||||
class="w-full sm:w-auto text-xs rounded-xl border border-slate-200 bg-white px-2.5 sm:px-3 py-2.5 text-slate-700 font-semibold focus:outline-none focus:border-[#1b5e20] focus:ring-2 focus:ring-[#1b5e20]/10 shadow-sm transition truncate">
|
||||
<option value="20" {{ request('per_page', '20') == '20' ? 'selected' : '' }}>20 / Hal</option>
|
||||
<option value="50" {{ request('per_page') == '50' ? 'selected' : '' }}>50 / Hal</option>
|
||||
<option value="100" {{ request('per_page') == '100' ? 'selected' : '' }}>Semua (100)</option>
|
||||
</select>
|
||||
|
||||
<!-- Tombol Submit Pencarian -->
|
||||
<button type="submit" class="px-4 py-2.5 bg-slate-900 hover:bg-slate-800 text-white text-xs font-bold rounded-xl transition shadow-sm cursor-pointer whitespace-nowrap col-span-2 sm:col-span-1">
|
||||
Cari
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<!-- Tombol Reset Filter (Sesuai Referensi Merah / Rose Clean Text) -->
|
||||
<div id="simperResetContainer">
|
||||
@if(request()->anyFilled(['search', 'employee_type', 'driver_status', 'simper_status']))
|
||||
@if(request()->anyFilled(['search', 'employee_type', 'driver_status', 'simper_status', 'per_page']))
|
||||
<a href="{{ route('hse.employees.index') }}"
|
||||
id="simperResetBtn"
|
||||
class="text-xs text-rose-600 hover:text-rose-700 font-semibold flex items-center justify-center sm:justify-start space-x-1.5 transition whitespace-nowrap py-1 sm:py-0 sm:ml-2">
|
||||
@@ -1217,87 +1231,22 @@
|
||||
document.getElementById('renewModal').classList.remove('hidden');
|
||||
}
|
||||
|
||||
// Filter Pencarian Instan Real-time
|
||||
// Pencarian Server-side Otomatis (Global ke seluruh database)
|
||||
const employeeFilterForm = document.getElementById('employeeFilterForm');
|
||||
const searchInput = document.getElementById('simperSearchInput');
|
||||
const resetContainer = document.getElementById('simperResetContainer');
|
||||
const tableBody = document.getElementById('simperTableBody');
|
||||
const hasServerFilters = {{ request()->anyFilled(['search', 'driver_status', 'simper_status']) ? 'true' : 'false' }};
|
||||
let searchDebounce = null;
|
||||
|
||||
function escapeHtml(str) {
|
||||
const div = document.createElement('div');
|
||||
div.textContent = str;
|
||||
return div.innerHTML;
|
||||
if (searchInput && searchInput.value) {
|
||||
searchInput.focus();
|
||||
const len = searchInput.value.length;
|
||||
searchInput.setSelectionRange(len, len);
|
||||
}
|
||||
|
||||
searchInput?.addEventListener('input', function(e) {
|
||||
const rawValue = e.target.value;
|
||||
const query = rawValue.toLowerCase().trim();
|
||||
const rows = document.querySelectorAll('#simperTableBody tr.simper-row');
|
||||
let visibleCount = 0;
|
||||
|
||||
rows.forEach(row => {
|
||||
const text = row.textContent.toLowerCase();
|
||||
const match = text.includes(query);
|
||||
row.style.display = match ? '' : 'none';
|
||||
if (match) visibleCount++;
|
||||
});
|
||||
|
||||
const serverEmptyRow = document.getElementById('serverSimperEmptyRow');
|
||||
if (serverEmptyRow) {
|
||||
serverEmptyRow.style.display = query.length > 0 ? 'none' : '';
|
||||
}
|
||||
|
||||
// Hapus baris pesan kosong pencarian jika ada sebelumnya
|
||||
const existingEmptyRow = document.getElementById('simperEmptySearchRow');
|
||||
if (existingEmptyRow) {
|
||||
existingEmptyRow.remove();
|
||||
}
|
||||
|
||||
// Tampilkan pesan jika tidak ada data yang cocok di tabel
|
||||
if (visibleCount === 0 && query.length > 0) {
|
||||
const emptyTr = document.createElement('tr');
|
||||
emptyTr.id = 'simperEmptySearchRow';
|
||||
emptyTr.innerHTML = `
|
||||
<td colspan="8" class="py-12 text-center text-slate-400">
|
||||
<i class="fa-solid fa-magnifying-glass text-3xl mb-3 block text-slate-300"></i>
|
||||
<p class="text-sm font-semibold text-slate-700">
|
||||
Data "<span class="text-rose-600 font-bold">${escapeHtml(rawValue)}</span>" tidak ditemukan di tabel
|
||||
</p>
|
||||
<p class="text-xs text-slate-400 mt-1">
|
||||
Pastikan ejaan NIK atau nama karyawan yang dicari sudah benar.
|
||||
</p>
|
||||
<div class="mt-4">
|
||||
<button type="button"
|
||||
onclick="const inp = document.getElementById('simperSearchInput'); if(inp){ inp.value=''; inp.dispatchEvent(new Event('input')); inp.focus(); }"
|
||||
class="inline-flex items-center space-x-1.5 px-3.5 py-2 rounded-xl text-xs font-semibold text-rose-600 bg-rose-50 border border-rose-200 hover:bg-rose-100 transition cursor-pointer">
|
||||
<i class="fa-solid fa-rotate-left text-[11px]"></i>
|
||||
<span>Hapus Pencarian</span>
|
||||
</button>
|
||||
</div>
|
||||
</td>
|
||||
`;
|
||||
tableBody?.appendChild(emptyTr);
|
||||
}
|
||||
|
||||
// Tampilkan/sembunyikan tombol Reset Filter secara real-time saat mengetik
|
||||
let resetBtn = document.getElementById('simperResetBtn');
|
||||
if (query.length > 0) {
|
||||
if (!resetBtn && resetContainer) {
|
||||
resetBtn = document.createElement('a');
|
||||
resetBtn.id = 'simperResetBtn';
|
||||
resetBtn.href = "{{ route('hse.employees.index') }}";
|
||||
resetBtn.className = "text-xs text-rose-600 hover:text-rose-700 font-semibold flex items-center justify-center sm:justify-start space-x-1.5 transition whitespace-nowrap py-1 sm:py-0 sm:ml-2";
|
||||
const resetIcon = document.createElement('i');
|
||||
resetIcon.className = "fa-solid fa-rotate-left text-[11px]";
|
||||
const resetText = document.createElement('span');
|
||||
resetText.textContent = "Reset Filter";
|
||||
resetBtn.appendChild(resetIcon);
|
||||
resetBtn.appendChild(resetText);
|
||||
resetContainer.appendChild(resetBtn);
|
||||
}
|
||||
} else if (!hasServerFilters && resetBtn) {
|
||||
resetBtn.remove();
|
||||
}
|
||||
searchInput?.addEventListener('input', function() {
|
||||
clearTimeout(searchDebounce);
|
||||
searchDebounce = setTimeout(function() {
|
||||
employeeFilterForm?.submit();
|
||||
}, 500);
|
||||
});
|
||||
|
||||
// Toggle Menu Dropdown Ekspor Simper (Format it.allrole.web.id)
|
||||
|
||||
Reference in New Issue
Block a user