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>
|
<script>
|
||||||
import DataContainer from '@/mixins/data-container';
|
import DataContainer from '@/mixins/data-container';
|
||||||
import router from '../router';
|
import router from '../router';
|
||||||
import {mapState} from 'vuex';
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'Cards',
|
name: 'Cards',
|
||||||
|
@ -51,16 +50,10 @@ export default {
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
changeFilter(col, val) {
|
changeFilter(col, val) {
|
||||||
console.log('filter:', col, val);
|
|
||||||
this.setFilter(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), {});
|
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});
|
router.push({query: newquery});
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
computed: {
|
|
||||||
...mapState(['route'])
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -3,12 +3,26 @@
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="col" v-for="(column, index) in columns" :key="index">
|
<th scope="col" v-for="(column, index) in columns" :key="index">
|
||||||
<button class="btn text-light" @click="toggleSort(column)">
|
<div class="input-group">
|
||||||
|
<div class="input-group-prepend">
|
||||||
|
<button
|
||||||
|
:class="[ 'btn', column === sortBy ? 'btn-outline-info' : 'btn-outline-secondary' ]"
|
||||||
|
@click="toggleSort(column)"
|
||||||
|
>
|
||||||
{{ column }}
|
{{ column }}
|
||||||
<span :class="{ 'text-info': column === sortBy }">
|
<span :class="{ 'text-info': column === sortBy }">
|
||||||
<font-awesome-icon :icon="getSortIcon(column)"/>
|
<font-awesome-icon :icon="getSortIcon(column)"/>
|
||||||
</span>
|
</span>
|
||||||
</button>
|
</button>
|
||||||
|
</div>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
class="form-control"
|
||||||
|
placeholder="filter"
|
||||||
|
:value="filters[column]"
|
||||||
|
@input="changeFilter(column, $event.target.value)"
|
||||||
|
>
|
||||||
|
</div>
|
||||||
</th>
|
</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
|
@ -22,10 +36,21 @@
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import DataContainer from '@/mixins/data-container';
|
import DataContainer from '@/mixins/data-container';
|
||||||
|
import router from '../router';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'Table',
|
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>
|
</script>
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue