c3lf-system-3/web/src/components/Table.vue

65 lines
2.3 KiB
Vue
Raw Normal View History

2019-11-14 03:37:35 +00:00
<template>
<table class="table table-striped table-dark">
<thead>
2019-11-14 18:30:00 +00:00
<tr>
<th scope="col" v-for="(column, index) in columns" :key="index">
2019-12-12 23:41:35 +00:00
<div class="input-group">
<div class="input-group-prepend">
<button
:class="[ 'btn', column === sortBy ? 'btn-outline-info' : 'btn-outline-secondary' ]"
@click="toggleSort(column)"
>
{{ column }}
<span :class="{ 'text-info': column === sortBy }">
<font-awesome-icon :icon="getSortIcon(column)"/>
</span>
</button>
</div>
<input
type="text"
class="form-control"
placeholder="filter"
:value="filters[column]"
@input="changeFilter(column, $event.target.value)"
>
</div>
2019-11-14 18:30:00 +00:00
</th>
2019-12-24 13:40:01 +00:00
<th></th>
2019-11-14 18:30:00 +00:00
</tr>
2019-11-14 03:37:35 +00:00
</thead>
2019-11-14 18:30:00 +00:00
<tbody>
<tr v-for="item in internalItems" :key="item[keyName]" @click="$emit('itemActivated', item)">
2019-11-14 18:30:00 +00:00
<td v-for="(column, index) in columns" :key="index">{{ item[column] }}</td>
<td>
2019-12-24 13:40:01 +00:00
<slot v-bind:item="item"/>
</td>
2019-11-14 18:30:00 +00:00
</tr>
</tbody>
2019-11-14 03:37:35 +00:00
</table>
</template>
<script>
2019-11-15 19:00:40 +00:00
import DataContainer from '@/mixins/data-container';
2019-12-12 23:41:35 +00:00
import router from '../router';
2019-11-14 18:30:00 +00:00
2019-11-14 03:37:35 +00:00
export default {
name: 'Table',
2019-12-12 23:41:35 +00:00
mixins: [DataContainer],
created() {
this.columns.map(e => ({k: e, v: this.$store.getters.getFilters[e]})).filter(e => e.v).forEach(e => this.setFilter(e.k, e.v));
},
methods: {
changeFilter(col, val) {
this.setFilter(col, val);
let newquery = Object.entries({...this.$store.getters.getFilters, [col]: val}).reduce((a,[k,v]) => (v ? {...a, [k]:v} : a), {});
router.push({query: newquery});
},
},
2019-11-14 03:37:35 +00:00
};
2019-11-14 18:30:00 +00:00
</script>
<style>
.table-body-move {
transition: transform 1s;
}
</style>