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:
@@ -86,11 +86,8 @@
|
||||
@endif
|
||||
|
||||
<!-- Kotak Pencarian & Filter Status Unit Fisik -->
|
||||
<div class="flex flex-col sm:flex-row items-stretch sm:items-center justify-between gap-3">
|
||||
<form method="GET" action="{{ route('qma.vehicles.support.units', $category->id) }}" class="relative w-full max-w-sm sm:max-w-md">
|
||||
@if(request('status'))
|
||||
<input type="hidden" name="status" value="{{ request('status') }}">
|
||||
@endif
|
||||
<form method="GET" action="{{ route('qma.vehicles.support.units', $category->id) }}" id="unitFilterForm" class="flex flex-col sm:flex-row items-stretch sm:items-center justify-between gap-3">
|
||||
<div class="relative w-full max-w-sm sm:max-w-md">
|
||||
<span class="absolute inset-y-0 left-0 pl-3.5 flex items-center pointer-events-none text-slate-400">
|
||||
<i class="fa-solid fa-magnifying-glass text-xs"></i>
|
||||
</span>
|
||||
@@ -100,25 +97,31 @@
|
||||
value="{{ request('search') }}"
|
||||
placeholder="Cari kode unit fisik, lokasi, SILO..."
|
||||
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-emerald-600 focus:ring-2 focus:ring-emerald-600/10 shadow-sm transition">
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div class="flex flex-wrap items-center gap-2">
|
||||
<!-- Filter Status Dropdown -->
|
||||
<form method="GET" action="{{ route('qma.vehicles.support.units', $category->id) }}" class="flex items-center space-x-2">
|
||||
@if(request('search'))
|
||||
<input type="hidden" name="search" value="{{ request('search') }}">
|
||||
@endif
|
||||
<select name="status" onchange="this.form.submit()" class="text-xs rounded-xl border border-slate-200 bg-white px-3 py-2 text-slate-700 font-semibold focus:outline-none focus:border-[#1b5e20] shadow-sm cursor-pointer">
|
||||
<option value="">Semua Status</option>
|
||||
<option value="Operation" {{ request('status') === 'Operation' ? 'selected' : '' }}>Operation</option>
|
||||
<option value="Standby" {{ request('status') === 'Standby' ? 'selected' : '' }}>Standby</option>
|
||||
<option value="Breakdown" {{ request('status') === 'Breakdown' ? 'selected' : '' }}>Breakdown</option>
|
||||
<option value="Maintenance" {{ request('status') === 'Maintenance' ? 'selected' : '' }}>Maintenance</option>
|
||||
</select>
|
||||
</form>
|
||||
<select name="status" onchange="this.form.submit()" class="text-xs rounded-xl border border-slate-200 bg-white px-3 py-2 text-slate-700 font-semibold focus:outline-none focus:border-[#1b5e20] shadow-sm cursor-pointer">
|
||||
<option value="">Semua Status</option>
|
||||
<option value="Operation" {{ request('status') === 'Operation' ? 'selected' : '' }}>Operation</option>
|
||||
<option value="Standby" {{ request('status') === 'Standby' ? 'selected' : '' }}>Standby</option>
|
||||
<option value="Breakdown" {{ request('status') === 'Breakdown' ? 'selected' : '' }}>Breakdown</option>
|
||||
<option value="Maintenance" {{ request('status') === 'Maintenance' ? 'selected' : '' }}>Maintenance</option>
|
||||
</select>
|
||||
|
||||
<!-- Filter Jumlah Per Halaman -->
|
||||
<select name="per_page" onchange="this.form.submit()" class="text-xs rounded-xl border border-slate-200 bg-white px-3 py-2 text-slate-700 font-semibold focus:outline-none focus:border-[#1b5e20] shadow-sm cursor-pointer">
|
||||
<option value="15" {{ request('per_page', '15') == '15' ? 'selected' : '' }}>15 / Hal</option>
|
||||
<option value="50" {{ request('per_page', '50') == '50' ? 'selected' : '' }}>50 / Hal</option>
|
||||
<option value="100" {{ request('per_page', '100') == '100' ? 'selected' : '' }}>Semua (100)</option>
|
||||
</select>
|
||||
|
||||
<button type="submit" class="px-4 py-2 bg-slate-900 hover:bg-slate-800 text-white text-xs font-bold rounded-xl transition shadow-sm cursor-pointer whitespace-nowrap">
|
||||
Cari
|
||||
</button>
|
||||
|
||||
<div id="unitResetWrapper" class="flex items-center">
|
||||
@if(request('search') || request('status'))
|
||||
@if(request()->anyFilled(['search', 'status', 'per_page']))
|
||||
<a id="unitResetBtn" href="{{ route('qma.vehicles.support.units', $category->id) }}" class="text-xs text-rose-600 hover:text-rose-800 font-semibold flex items-center space-x-1 whitespace-nowrap ml-1">
|
||||
<i class="fa-solid fa-rotate-left text-[11px]"></i>
|
||||
<span>Reset Filter</span>
|
||||
@@ -126,7 +129,7 @@
|
||||
@endif
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<!-- Tabel Data Unit Fisik (Header Navy Solid #06213f) -->
|
||||
<div class="bg-white rounded-none sm:rounded-2xl border border-slate-200 shadow-sm overflow-hidden">
|
||||
@@ -958,87 +961,21 @@
|
||||
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
const searchInput = document.getElementById('unitSearchInput');
|
||||
const tableBody = document.getElementById('unitsTableBody');
|
||||
const resetWrapper = document.getElementById('unitResetWrapper');
|
||||
const paginationContainer = document.getElementById('unitsPaginationContainer');
|
||||
const serverEmptyRow = document.getElementById('serverUnitEmptyRow');
|
||||
const hasServerFilters = {{ request()->anyFilled(['status']) ? 'true' : 'false' }};
|
||||
const filterForm = document.getElementById('unitFilterForm');
|
||||
let searchDebounce = null;
|
||||
|
||||
if (searchInput && tableBody) {
|
||||
searchInput.addEventListener('input', function (e) {
|
||||
const rawValue = e.target.value;
|
||||
const query = rawValue.toLowerCase().trim();
|
||||
const rows = tableBody.querySelectorAll('tr.unit-row');
|
||||
let visibleCount = 0;
|
||||
|
||||
rows.forEach(row => {
|
||||
const text = row.textContent.toLowerCase();
|
||||
if (text.includes(query)) {
|
||||
row.style.display = '';
|
||||
visibleCount++;
|
||||
} else {
|
||||
row.style.display = 'none';
|
||||
}
|
||||
});
|
||||
|
||||
if (paginationContainer) {
|
||||
paginationContainer.style.display = query.length > 0 ? 'none' : '';
|
||||
}
|
||||
|
||||
const existingEmptyRow = document.getElementById('clientUnitEmptyRow');
|
||||
if (existingEmptyRow) existingEmptyRow.remove();
|
||||
|
||||
if (serverEmptyRow) {
|
||||
serverEmptyRow.style.display = query.length > 0 ? 'none' : '';
|
||||
}
|
||||
|
||||
if (visibleCount === 0 && query.length > 0) {
|
||||
const emptyTr = document.createElement('tr');
|
||||
emptyTr.id = 'clientUnitEmptyRow';
|
||||
emptyTr.innerHTML = `
|
||||
<td colspan="10" 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 kata kunci yang dicari sudah benar.
|
||||
</p>
|
||||
<div class="mt-4">
|
||||
<button type="button"
|
||||
onclick="const inp = document.getElementById('unitSearchInput'); 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);
|
||||
}
|
||||
|
||||
if (resetWrapper) {
|
||||
let resetBtn = document.getElementById('unitResetBtn');
|
||||
if (query.length > 0 || hasServerFilters) {
|
||||
if (!resetBtn) {
|
||||
resetBtn = document.createElement('a');
|
||||
resetBtn.id = 'unitResetBtn';
|
||||
resetBtn.href = "{{ route('qma.vehicles.support.units', $category->id) }}";
|
||||
resetBtn.className = 'text-xs text-rose-600 hover:text-rose-800 font-semibold flex items-center space-x-1 whitespace-nowrap ml-1';
|
||||
resetBtn.innerHTML = '<i class="fa-solid fa-rotate-left text-[11px]"></i><span>Reset Filter</span>';
|
||||
resetWrapper.appendChild(resetBtn);
|
||||
}
|
||||
} else if (!hasServerFilters && resetBtn) {
|
||||
resetBtn.remove();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Trigger saat awal memuat halaman jika ada nilai pencarian dari SSR
|
||||
if (searchInput.value.trim() !== '') {
|
||||
searchInput.dispatchEvent(new Event('input'));
|
||||
}
|
||||
if (searchInput && searchInput.value) {
|
||||
searchInput.focus();
|
||||
const len = searchInput.value.length;
|
||||
searchInput.setSelectionRange(len, len);
|
||||
}
|
||||
|
||||
searchInput?.addEventListener('input', function() {
|
||||
clearTimeout(searchDebounce);
|
||||
searchDebounce = setTimeout(function() {
|
||||
filterForm?.submit();
|
||||
}, 500);
|
||||
});
|
||||
});
|
||||
|
||||
// Dropdown Menu Ekspor Heavy Equipment Kategori Ini
|
||||
|
||||
Reference in New Issue
Block a user