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

61 lines
2.2 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>
</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>
</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>