Skip to content

Commit

Permalink
fix(desktop): keep filter text when data changes on tree view
Browse files Browse the repository at this point in the history
  • Loading branch information
ysfscream authored and Red-Asuka committed Oct 15, 2024
1 parent 169ce1e commit 3b63bcd
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions src/components/widgets/TreeView.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<div class="tree-view">
<div class="tree-view-header">
<el-input :placeholder="$t('viewer.filterDesc')" size="small" v-model="filterText" class="mb-3" />
<el-input :placeholder="$t('viewer.filterDesc')" size="small" v-model="filterText" class="mb-3" clearable />
</div>
<el-tree
ref="tree"
Expand Down Expand Up @@ -53,7 +53,19 @@ export default class TreeView extends Vue {
@Watch('filterText')
private filterTextChange(val: string) {
this.treeRef.filter(val)
this.$nextTick(() => {
this.treeRef.filter(val)
})
}
@Watch('data', { deep: true })
private onDataChange() {
this.$nextTick(() => {
// Keep the filter text when data changes
if (this.filterText) {
this.treeRef.filter(this.filterText)
}
})
}
private defaultProps = {
Expand Down Expand Up @@ -89,6 +101,15 @@ export default class TreeView extends Vue {
node.children.forEach((child) => this.removeExpandedKeysRecursively(child))
}
}
mounted() {
// Keep the filter text when data changes
this.$nextTick(() => {
if (this.filterText) {
this.treeRef.filter(this.filterText)
}
})
}
}
</script>

Expand Down

0 comments on commit 3b63bcd

Please sign in to comment.