Skip to content

Commit

Permalink
fixing exportable bug (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
havok2063 authored Aug 14, 2024
1 parent edc92ea commit 78e7d98
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions src/views/Results.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<v-container fluid>
<v-row dense no-gutters class="d-flex align-center">
<v-col cols="auto" class="d-flex align-center">
<v-btn variant='plain' density="compact" @mouseover="dialog = true" icon="mdi-help-circle-outline"></v-btn>
<v-btn color='warning' variant='outlined' density="compact" @mouseover="dialog = true" icon="mdi-help"></v-btn>
<h1 class="ml-2">Results</h1>
</v-col>
</v-row>
Expand Down Expand Up @@ -310,16 +310,22 @@ const downloadBlob = (data: Array<Object>, filename: string, mimeType: string) =
a.download = filename
a.click()
window.URL.revokeObjectURL(url)
// reset the export table button
exportas.value = null
}
const exportToCsv = () => {
// export the table to CSV
let csvRows = [];
// Add header
csvRows.push(headers.value.map(e => e.title).join(","));
// Add header, use the original column name
csvRows.push(headers.value.map(e => e.key).join(","));
// get the selected rows or all rows if none selected
let rows = selected.value.length > 0 ? selected.value : data.value
// Add data
selected.value.forEach(row => {
rows.forEach(row => {
let rowData = headers.value.map(header => JSON.stringify(row[header.key], (_, value) => {
// Custom formatting can go here
return value
Expand All @@ -334,8 +340,12 @@ const exportToCsv = () => {
const exportToJson = () => {
// export the table to JSON
// get the selected rows or all rows if none selected
let rows = selected.value.length > 0 ? selected.value : data.value
const filename = "sdss_table_export.json"
const jsonContent = JSON.stringify(selected.value)
const jsonContent = JSON.stringify(rows, null, 2)
downloadBlob(jsonContent, filename, "application/json")
}
Expand Down

0 comments on commit 78e7d98

Please sign in to comment.