Feature: CSV-Export der Suchergebnisse

This commit is contained in:
2025-03-21 12:04:17 +01:00
parent b4939147c4
commit d14ac5d9af
3 changed files with 81 additions and 0 deletions

View File

@@ -124,6 +124,78 @@ function updateResultCounts() {
document.getElementById('resultCount').textContent =
generalCount > 0 ? `${generalCount} Treffer gefunden` : '';
document.getElementById('resultCount').classList.toggle('visible', generalCount > 0);
// Export-Button anzeigen/verstecken
document.getElementById('exportButton').style.display = generalCount > 0 ? 'inline-block' : 'none';
}
function exportToCSV() {
if (!lastResults || lastResults.length === 0) return;
// CSV-Header definieren
const headers = [
'Nummer',
'Name',
'Fachrichtung',
'Straße',
'PLZ',
'Ort',
'Telefon',
'Mobil',
'Handy',
'Telefon Firma',
'E-Mail',
'Kontakt 1',
'Kontakt 2',
'Kontakt 3',
'Tags'
];
// CSV-Daten erstellen
const csvRows = [headers];
lastResults.forEach(customer => {
const row = [
customer.nummer,
customer.name,
customer.fachrichtung,
customer.strasse,
customer.plz,
customer.ort,
customer.telefon,
customer.mobil,
customer.handy,
customer.tele_firma,
customer.email,
customer.kontakt1,
customer.kontakt2,
customer.kontakt3,
(customer.tags || []).join(';')
].map(value => {
// Werte mit Kommas oder Anführungszeichen in Anführungszeichen setzen
if (value && (value.includes(',') || value.includes('"') || value.includes('\n'))) {
return `"${value.replace(/"/g, '""')}"`;
}
return value || '';
});
csvRows.push(row);
});
// CSV-String erstellen
const csvContent = csvRows.map(row => row.join(',')).join('\n');
// Blob erstellen und Download starten
const blob = new Blob([csvContent], { type: 'text/csv;charset=utf-8;' });
const link = document.createElement('a');
const url = URL.createObjectURL(blob);
link.setAttribute('href', url);
link.setAttribute('download', `kundensuche_${new Date().toISOString().split('T')[0]}.csv`);
link.style.visibility = 'hidden';
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
}
function displayResults(results) {