add filters to table view
This commit is contained in:
parent
99107f4583
commit
62a26f4f9c
2 changed files with 32 additions and 14 deletions
|
@ -41,7 +41,6 @@
|
|||
<script>
|
||||
import DataContainer from '@/mixins/data-container';
|
||||
import router from '../router';
|
||||
import {mapState} from 'vuex';
|
||||
|
||||
export default {
|
||||
name: 'Cards',
|
||||
|
@ -51,16 +50,10 @@ export default {
|
|||
},
|
||||
methods: {
|
||||
changeFilter(col, val) {
|
||||
console.log('filter:', 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), {});
|
||||
console.log(this.$store.getters.getFilters);
|
||||
console.log('query:', newquery);
|
||||
router.push({query: newquery});
|
||||
},
|
||||
},
|
||||
computed: {
|
||||
...mapState(['route'])
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
|
|
@ -3,12 +3,26 @@
|
|||
<thead>
|
||||
<tr>
|
||||
<th scope="col" v-for="(column, index) in columns" :key="index">
|
||||
<button class="btn text-light" @click="toggleSort(column)">
|
||||
{{ column }}
|
||||
<span :class="{ 'text-info': column === sortBy }">
|
||||
<font-awesome-icon :icon="getSortIcon(column)"/>
|
||||
</span>
|
||||
</button>
|
||||
<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>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
@ -22,10 +36,21 @@
|
|||
|
||||
<script>
|
||||
import DataContainer from '@/mixins/data-container';
|
||||
import router from '../router';
|
||||
|
||||
export default {
|
||||
name: 'Table',
|
||||
mixins: [DataContainer]
|
||||
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});
|
||||
},
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
||||
|
|
Loading…
Reference in a new issue