Skip to content

Commit

Permalink
[feature] export innerText of statistics table as CSV file #47
Browse files Browse the repository at this point in the history
limitation: only one table can be copied in each file
  • Loading branch information
alex-rind committed Dec 4, 2021
1 parent c8e22e2 commit 639b1c8
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/assets/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function download(filename: string, dataURL: string): void {
export function downloadText(filename: string, text: string): void {
download(
filename,
"data:text/plain;charset=utf-8," + encodeURIComponent(text)
"data:text/plain;charset=utf-8,\ufeff" + encodeURIComponent(text)
);
}

Expand Down
31 changes: 29 additions & 2 deletions src/components/StatisticsTable.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<div class="panel-block" style="display: block">
<table class="table">
<table class="table is-fullwidth" ref="domTable">
<!-- <thead>
<tr>
<th><abbr title="Position">Pos</abbr></th>
Expand Down Expand Up @@ -59,11 +59,26 @@
</tr>
</tbody>
</table>
<div class="buttons is-centered">
<!-- <button class="button" type="button" @click.stop="toggleHorizons">
<span class="icon">
<font-awesome-icon icon="file-csv" />
</span>
<span>in Zwischenablage kopieren</span>
</button> -->

<button class="button" type="button" @click.stop="exportCSV">
<span class="icon">
<font-awesome-icon icon="file-csv" />
</span>
<span>als CSV speichern</span>
</button>
</div>
</div>
</template>

<script lang="ts">
import { computed, defineComponent } from "vue";
import { computed, defineComponent, ref } from "vue";
import { useStore } from "@/store";
import {
analyseNWKbyCategory,
Expand All @@ -72,6 +87,7 @@ import {
NetworkAnalysis,
} from "@/data/NetworkAnalysis";
import { getAlterCategorization } from "@/data/AlterCategories";
import { downloadText } from "@/assets/utils";
export default defineComponent({
setup() {
Expand Down Expand Up @@ -129,6 +145,15 @@ export default defineComponent({
}
};
const domTable = ref<InstanceType<typeof HTMLTableElement> | null>(null);
const exportCSV = () => {
downloadText(
"statistics.csv",
(domTable.value as HTMLTableElement).innerText.replaceAll("\t", ";")
);
};
return {
networkSize: computed(() => networkAnalysis.value.alterConnected),
naehenSum: computed(() => networkAnalysis.value.naehenSum),
Expand All @@ -139,6 +164,8 @@ export default defineComponent({
bridgePersons: makeComputedAlterGroup("bridgePersons"),
bridgesCount: computed(() => networkAnalysis.value.bridges.length),
clickCell,
exportCSV,
domTable,
};
},
});
Expand Down
2 changes: 1 addition & 1 deletion src/components/StatisticsTableCategories.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<div class="panel-block" style="display: block">
<table class="table">
<table class="table is-fullwidth">
<thead>
<tr>
<th></th>
Expand Down
2 changes: 2 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
faFile,
faSave,
faFileImage,
faFileCsv,
// faChevronDown,
// faUndoAlt,
// faRedoAlt,
Expand All @@ -50,6 +51,7 @@ library.add(
faFile,
faSave,
faFileImage,
faFileCsv,
// faChevronDown,
// faUndoAlt,
// faRedoAlt,
Expand Down

0 comments on commit 639b1c8

Please sign in to comment.