Fix product performance grouped JSON build
This commit is contained in:
@@ -40,6 +40,14 @@
|
||||
:loading="loading"
|
||||
@click="fetchRows"
|
||||
/>
|
||||
<q-btn
|
||||
label="Excel'e Aktar"
|
||||
icon="download"
|
||||
color="primary"
|
||||
outline
|
||||
:disable="loading || rows.length === 0"
|
||||
@click="exportVisibleRows"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -374,6 +382,38 @@ function clearFilters () {
|
||||
fetchRows()
|
||||
}
|
||||
|
||||
function escapeExcelCsvCell (value) {
|
||||
let text = String(value ?? '')
|
||||
// Prevent spreadsheet applications from evaluating data as a formula.
|
||||
if (/^[=+\-@]/.test(text)) text = `'${text}`
|
||||
return `"${text.replace(/"/g, '""')}"`
|
||||
}
|
||||
|
||||
function exportVisibleRows () {
|
||||
const visibleRows = Array.isArray(rows.value) ? rows.value : []
|
||||
if (visibleRows.length === 0) return
|
||||
|
||||
const exportColumns = columns.filter(col => col.name !== 'open')
|
||||
const csvLines = [
|
||||
exportColumns.map(col => escapeExcelCsvCell(col.label)).join(';'),
|
||||
...visibleRows.map(row => exportColumns.map(col => {
|
||||
const rawValue = typeof col.field === 'function' ? col.field(row) : row?.[col.field]
|
||||
const displayValue = typeof col.format === 'function' ? col.format(rawValue, row) : rawValue
|
||||
return escapeExcelCsvCell(displayValue)
|
||||
}).join(';'))
|
||||
]
|
||||
|
||||
const blob = new Blob([`\uFEFF${csvLines.join('\r\n')}`], { type: 'text/csv;charset=utf-8;' })
|
||||
const url = URL.createObjectURL(blob)
|
||||
const link = document.createElement('a')
|
||||
link.href = url
|
||||
link.download = `mevcut_maliyetli_urunler_${new Date().toISOString().slice(0, 10)}.csv`
|
||||
document.body.appendChild(link)
|
||||
link.click()
|
||||
link.remove()
|
||||
URL.revokeObjectURL(url)
|
||||
}
|
||||
|
||||
function openRow (row) {
|
||||
const urunKodu = String(row?.UrunKodu || '').trim()
|
||||
if (!urunKodu) return
|
||||
|
||||
Reference in New Issue
Block a user