antares/src/renderer/components/WorkspaceQueryTable.vue

108 lines
2.6 KiB
Vue
Raw Normal View History

2020-06-10 19:29:10 +02:00
<template>
2020-06-11 23:34:38 +02:00
<BaseVirtualScroll
v-if="results.rows"
ref="resultTable"
:items="results.rows"
:item-height="25"
class="vscroll"
:style="{'height': resultsSize+'px'}"
>
<template slot-scope="{ items }">
<div class="table table-hover">
<div class="thead">
<div class="tr">
<div
v-for="field in results.fields"
:key="field.name"
class="th"
>
{{ field.name }}
</div>
</div>
2020-06-10 19:29:10 +02:00
</div>
2020-06-11 23:34:38 +02:00
<div class="tbody">
<div
v-for="(row, rKey) in items"
:key="rKey"
class="tr"
tabindex="0"
>
<div
v-for="(col, cKey) in row"
:key="cKey"
class="td"
:class="fieldType(col)"
>
{{ col }}
</div>
</div>
2020-06-10 19:29:10 +02:00
</div>
</div>
2020-06-11 23:34:38 +02:00
</template>
</BaseVirtualScroll>
2020-06-10 19:29:10 +02:00
</template>
<script>
2020-06-11 23:34:38 +02:00
import BaseVirtualScroll from '@/components/BaseVirtualScroll';
2020-06-10 19:29:10 +02:00
export default {
name: 'WorkspaceQueryTable',
2020-06-11 23:34:38 +02:00
components: {
BaseVirtualScroll
},
2020-06-10 19:29:10 +02:00
props: {
results: Object
},
2020-06-11 23:34:38 +02:00
data () {
return {
resultsSize: 1000
};
},
computed: {
rows () {
return this.results.rows ? this.results.rows.map(item => Object.assign({}, item)) : [];
}
},
watch: {
results: function () {
if (this.$refs.resultTable)
this.resizeResults();
}
},
mounted () {
window.addEventListener('resize', this.resizeResults);
},
destroyed () {
window.removeEventListener('resize', this.resizeResults);
},
2020-06-10 19:29:10 +02:00
methods: {
fieldType (col) {
let type = typeof col;
if (type === 'object')
if (col instanceof Date) type = 'date';
if (col instanceof Uint8Array) type = 'blob';
if (col === null) type = 'null';
return `type-${type}`;
2020-06-11 23:34:38 +02:00
},
resizeResults (e) {
const el = this.$refs.resultTable.$el;
const footer = document.getElementById('footer');
if (el) {
const size = window.innerHeight - el.getBoundingClientRect().top - footer.offsetHeight;
this.resultsSize = size;
}
2020-06-10 19:29:10 +02:00
}
}
};
</script>
<style>
2020-06-11 23:34:38 +02:00
.vscroll {
height: 1000px;
overflow: auto;
overflow-anchor: none;
}
2020-06-10 19:29:10 +02:00
</style>