2019-11-14 03:37:35 +00:00
|
|
|
<template>
|
|
|
|
<table class="table table-striped table-dark">
|
|
|
|
<thead>
|
2023-11-27 00:14:52 +00:00
|
|
|
<tr>
|
|
|
|
<th scope="col" v-for="(column, index) in columns" :key="index">
|
|
|
|
<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 }">
|
2019-12-12 23:41:35 +00:00
|
|
|
<font-awesome-icon :icon="getSortIcon(column)"/>
|
|
|
|
</span>
|
2023-11-27 00:14:52 +00:00
|
|
|
</button>
|
2019-12-12 23:41:35 +00:00
|
|
|
</div>
|
2023-11-27 00:14:52 +00:00
|
|
|
<input
|
|
|
|
type="text"
|
|
|
|
class="form-control"
|
|
|
|
placeholder="filter"
|
|
|
|
:value="filters[column]"
|
|
|
|
@input="changeFilter(column, $event.target.value)"
|
|
|
|
>
|
|
|
|
</div>
|
|
|
|
</th>
|
2023-12-28 21:49:55 +00:00
|
|
|
<th>
|
|
|
|
<slot name="header_actions"/>
|
|
|
|
</th>
|
2023-11-27 00:14:52 +00:00
|
|
|
</tr>
|
2019-11-14 03:37:35 +00:00
|
|
|
</thead>
|
2019-11-14 18:30:00 +00:00
|
|
|
<tbody>
|
2023-11-27 00:14:52 +00:00
|
|
|
<tr v-for="item in internalItems" :key="item[keyName]" @click="$emit('itemActivated', item)">
|
|
|
|
<td v-for="(column, index) in columns" :key="index">{{ item[column] }}</td>
|
|
|
|
<td>
|
2023-12-28 21:49:55 +00:00
|
|
|
<slot v-bind:item="item" name="actions"/>
|
2023-11-27 00:14:52 +00:00
|
|
|
</td>
|
|
|
|
</tr>
|
2019-11-14 18:30:00 +00:00
|
|
|
</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 {
|
2023-11-27 00:14:52 +00:00
|
|
|
name: 'Table',
|
|
|
|
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-12-12 23:41:35 +00:00
|
|
|
},
|
2019-11-14 03:37:35 +00:00
|
|
|
};
|
2019-11-14 18:30:00 +00:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<style>
|
2023-11-27 00:14:52 +00:00
|
|
|
.table-body-move {
|
|
|
|
transition: transform 1s;
|
|
|
|
}
|
2019-11-14 18:30:00 +00:00
|
|
|
</style>
|