table filter works again

This commit is contained in:
2022-03-22 11:41:58 +01:00
parent a4c99edc62
commit 9b58d7941f
4 changed files with 41 additions and 3 deletions
@@ -9,7 +9,7 @@
<template v-slot:footer>
<ui-button type="light onbg" label="@ui.close" @click="config.close"></ui-button>
<ui-button v-if="!model.isCreate" type="light onbg" label="@ui.remove" @click="onRemove"></ui-button>
<ui-button type="accent" :submit="true" label="@ui.confirm" :state="form.state" :disabled="loading || disabled"></ui-button>
<ui-button type="accent" :submit="true" label="@ui.confirm" :state="form.state" :disabled="loading || disabled || !filterName"></ui-button>
</template>
<ui-loading v-if="loading" :is-big="true" />
@@ -101,6 +101,18 @@
this.storedFilters = this.getStoredFilters();
this.actions = this.attach.listConfig.actions;
let filterId = this.$route.query['filter'];
if (filterId)
{
let filter = this.storedFilters.find(x => x.id === filterId);
if (filter)
{
this.setFilter(filter);
}
}
this.loaded = true;
},
@@ -124,7 +136,7 @@
// set the current filter
setFilter(value, two)
setFilter(value)
{
if (!value)
{
+26 -1
View File
@@ -98,6 +98,7 @@
}
}
const FILTER_KEY_PREFIX = 'zero.ui-table-filter.';
export default defineComponent({
name: 'uiTable',
@@ -122,6 +123,7 @@
listConfig: {},
columns: [],
query: {},
alias: null,
filter: null,
items: [],
@@ -164,6 +166,7 @@
{
this.debouncedUpdate = debounce(this.update, 300);
const schema = typeof this.config === 'string' ? await this.zero.getSchema(this.config) : this.config;
this.alias = schema.alias;
this.listConfig = compileList(this.zero, schema);
this.itemComponentConfig = this.listConfig.componentConfig || { active: false };
//this.listConfig.selectable = true;
@@ -187,6 +190,18 @@
this.query = { ...this.listConfig.query, ...this.listConfig.queryToParams(this.$route.query) };
this.component = !!this.listConfig.link ? 'router-link' : (!!this.listConfig.onClick ? 'button' : 'div');
this.filter = { ...this.listConfig.filterOptions };
if (this.query.filter && this.query.filter.id)
{
let filters = this.getStoredFilters();
let filter = filters.find(x => x.id === this.query.filter.id);
if (filter)
{
this.query.filter = { ...filter.filter, id: filter.id };
}
}
this.$nextTick(() =>
{
this.loaded = true;
@@ -230,6 +245,17 @@
},
// load stored filters from local storage
getStoredFilters()
{
if (!this.filter.editor)
{
return [];
}
return JSON.parse(localStorage.getItem(FILTER_KEY_PREFIX + this.filter.editor.alias) || "[]");
},
// updates the list (debounced)
async update()
{
@@ -295,7 +321,6 @@
// set a new filter
setFilter(filter)
{
console.info('filter', filter);
this.query.filter = filter;
this.onChange();
},
@@ -105,6 +105,7 @@ class List implements ZeroSchema
{
values.filter = params.filter.id;
}
return values;
};