Trefferzähler für alle Suchfelder hinzugefügt
This commit is contained in:
@@ -97,6 +97,21 @@
|
||||
.search-field {
|
||||
position: relative;
|
||||
}
|
||||
.result-count {
|
||||
position: absolute;
|
||||
right: 10px;
|
||||
top: 50%;
|
||||
transform: translateY(-50%);
|
||||
background-color: #e9ecef;
|
||||
padding: 2px 8px;
|
||||
border-radius: 12px;
|
||||
font-size: 0.8em;
|
||||
color: #6c757d;
|
||||
display: none;
|
||||
}
|
||||
.result-count.visible {
|
||||
display: block;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
@@ -108,18 +123,22 @@
|
||||
<div class="search-field">
|
||||
<input type="text" id="nameInput" class="form-control"
|
||||
placeholder="Name...">
|
||||
<span id="nameCount" class="result-count"></span>
|
||||
</div>
|
||||
<div class="search-field">
|
||||
<input type="text" id="ortInput" class="form-control"
|
||||
placeholder="Ort...">
|
||||
<span id="ortCount" class="result-count"></span>
|
||||
</div>
|
||||
<div class="search-field">
|
||||
<input type="text" id="kundennummerInput" class="form-control"
|
||||
placeholder="Kundennummer...">
|
||||
<span id="kundennummerCount" class="result-count"></span>
|
||||
</div>
|
||||
<div class="search-field">
|
||||
<input type="text" id="fachrichtungInput" class="form-control"
|
||||
placeholder="Fachrichtung...">
|
||||
<span id="fachrichtungCount" class="result-count"></span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -127,6 +146,7 @@
|
||||
<input type="text" id="searchInput" class="form-control form-control-lg"
|
||||
placeholder="Allgemeine Suche...">
|
||||
<span class="search-icon">🔍</span>
|
||||
<span id="generalCount" class="result-count"></span>
|
||||
</div>
|
||||
|
||||
<div id="loading" class="loading">
|
||||
@@ -151,6 +171,7 @@
|
||||
|
||||
<script>
|
||||
let searchTimeout;
|
||||
let lastResults = [];
|
||||
|
||||
function createPhoneLink(phone) {
|
||||
if (!phone) return 'N/A';
|
||||
@@ -205,6 +226,44 @@
|
||||
}
|
||||
}
|
||||
|
||||
function updateResultCounts() {
|
||||
const name = document.getElementById('nameInput').value;
|
||||
const ort = document.getElementById('ortInput').value;
|
||||
const kundennummer = document.getElementById('kundennummerInput').value;
|
||||
const fachrichtung = document.getElementById('fachrichtungInput').value;
|
||||
const query = document.getElementById('searchInput').value;
|
||||
|
||||
// Zähler für spezifische Felder
|
||||
const nameCount = lastResults.filter(customer =>
|
||||
(customer.Vorname + ' ' + customer.Nachname).toLowerCase().includes(name.toLowerCase())
|
||||
).length;
|
||||
document.getElementById('nameCount').textContent = nameCount;
|
||||
document.getElementById('nameCount').classList.toggle('visible', nameCount > 0);
|
||||
|
||||
const ortCount = lastResults.filter(customer =>
|
||||
customer.Ort?.toLowerCase().includes(ort.toLowerCase())
|
||||
).length;
|
||||
document.getElementById('ortCount').textContent = ortCount;
|
||||
document.getElementById('ortCount').classList.toggle('visible', ortCount > 0);
|
||||
|
||||
const kundennummerCount = lastResults.filter(customer =>
|
||||
customer.Nummer?.toString().includes(kundennummer)
|
||||
).length;
|
||||
document.getElementById('kundennummerCount').textContent = kundennummerCount;
|
||||
document.getElementById('kundennummerCount').classList.toggle('visible', kundennummerCount > 0);
|
||||
|
||||
const fachrichtungCount = lastResults.filter(customer =>
|
||||
customer.Fachrichtung?.toLowerCase().includes(fachrichtung.toLowerCase())
|
||||
).length;
|
||||
document.getElementById('fachrichtungCount').textContent = fachrichtungCount;
|
||||
document.getElementById('fachrichtungCount').classList.toggle('visible', fachrichtungCount > 0);
|
||||
|
||||
// Zähler für allgemeine Suche
|
||||
const generalCount = lastResults.length;
|
||||
document.getElementById('generalCount').textContent = generalCount;
|
||||
document.getElementById('generalCount').classList.toggle('visible', generalCount > 0);
|
||||
}
|
||||
|
||||
function searchCustomers() {
|
||||
const name = document.getElementById('nameInput').value;
|
||||
const ort = document.getElementById('ortInput').value;
|
||||
@@ -215,6 +274,8 @@
|
||||
// Prüfe, ob mindestens ein Suchfeld ausgefüllt ist
|
||||
if (!name && !ort && !kundennummer && !fachrichtung && !query) {
|
||||
document.getElementById('results').innerHTML = '';
|
||||
lastResults = [];
|
||||
updateResultCounts();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -245,6 +306,8 @@
|
||||
|
||||
if (data.length === 0) {
|
||||
resultsDiv.innerHTML = '<div class="alert alert-info">Keine Ergebnisse gefunden.</div>';
|
||||
lastResults = [];
|
||||
updateResultCounts();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -272,11 +335,16 @@
|
||||
`;
|
||||
resultsDiv.appendChild(card);
|
||||
});
|
||||
|
||||
lastResults = data;
|
||||
updateResultCounts();
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Fehler:', error);
|
||||
document.getElementById('results').innerHTML =
|
||||
`<div class="alert alert-danger">${error.message}</div>`;
|
||||
lastResults = [];
|
||||
updateResultCounts();
|
||||
})
|
||||
.finally(() => {
|
||||
document.getElementById('loading').style.display = 'none';
|
||||
|
Reference in New Issue
Block a user