From 66e884024f4210e67c4ca6dd5d6eeb3bb04b8ae1 Mon Sep 17 00:00:00 2001
From: Gimmy <975402925@qq.com>
Date: Tue, 16 Apr 2024 20:29:11 +0800
Subject: [PATCH] fix(grid): [grid] fix remote filter default value
---
.../server-filter-default-composition-api.vue | 132 +++++++++++++++++
.../grid/filter/server-filter-default.spec.js | 9 ++
.../app/grid/filter/server-filter-default.vue | 139 ++++++++++++++++++
.../demos/pc/app/grid/webdoc/grid-filter.js | 11 ++
.../vue/src/grid/src/filter/src/methods.ts | 3 +
.../vue/src/grid/src/table/src/methods.ts | 5 +
6 files changed, 299 insertions(+)
create mode 100644 examples/sites/demos/pc/app/grid/filter/server-filter-default-composition-api.vue
create mode 100644 examples/sites/demos/pc/app/grid/filter/server-filter-default.spec.js
create mode 100644 examples/sites/demos/pc/app/grid/filter/server-filter-default.vue
diff --git a/examples/sites/demos/pc/app/grid/filter/server-filter-default-composition-api.vue b/examples/sites/demos/pc/app/grid/filter/server-filter-default-composition-api.vue
new file mode 100644
index 0000000000..3263970df6
--- /dev/null
+++ b/examples/sites/demos/pc/app/grid/filter/server-filter-default-composition-api.vue
@@ -0,0 +1,132 @@
+
+
+ 加载数据
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/examples/sites/demos/pc/app/grid/filter/server-filter-default.spec.js b/examples/sites/demos/pc/app/grid/filter/server-filter-default.spec.js
new file mode 100644
index 0000000000..7ef328708d
--- /dev/null
+++ b/examples/sites/demos/pc/app/grid/filter/server-filter-default.spec.js
@@ -0,0 +1,9 @@
+import { test, expect } from '@playwright/test'
+
+test('服务端过滤', async ({ page }) => {
+ page.on('pageerror', (exception) => expect(exception).toBeNull())
+ await page.goto('grid-filter#server-filter-default')
+ await page.waitForTimeout(3000)
+ await page.getByRole('button', { name: '加载数据' }).click()
+ await expect(page.locator('.tiny-grid-body__row')).toHaveCount(1)
+})
diff --git a/examples/sites/demos/pc/app/grid/filter/server-filter-default.vue b/examples/sites/demos/pc/app/grid/filter/server-filter-default.vue
new file mode 100644
index 0000000000..4eb7da4a94
--- /dev/null
+++ b/examples/sites/demos/pc/app/grid/filter/server-filter-default.vue
@@ -0,0 +1,139 @@
+
+
+ 加载数据
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/examples/sites/demos/pc/app/grid/webdoc/grid-filter.js b/examples/sites/demos/pc/app/grid/webdoc/grid-filter.js
index f8ef135b26..cb40f6ab58 100644
--- a/examples/sites/demos/pc/app/grid/webdoc/grid-filter.js
+++ b/examples/sites/demos/pc/app/grid/webdoc/grid-filter.js
@@ -97,6 +97,17 @@ export default {
},
'codeFiles': ['filter/server-filter.vue']
},
+ {
+ 'demoId': 'server-filter-default',
+ 'name': { 'zh-CN': '服务端过滤默认选中值', 'en-US': 'Server-side filtering default selected value' },
+ 'desc': {
+ 'zh-CN':
+ '
配置 remote-filter 开启服务端过滤后,表格初始化时,如果设置了 auto-load
会在表格列初始化钱调用 handleFetch
,因此此时无法获取到过滤参数,如果需要设置服务端过滤默认选中值,需将 auto-load
设置为false且手动调用一次 handleFetch
方法。
\n',
+ 'en-US':
+ 'Set the default input filtering options through the inputFilter.relation
attribute. \n Enter the built-in options for filtering: equals
, unequal
, greaterThan
, lessThan
, equalToGreaterThan
, equalToLessThan
, contains
, startwith
, endwith
; Custom options can also be configured. \n When configuring custom options, you need to configure the filtering method through the inputFilter.method
attribute.
\n'
+ },
+ 'codeFiles': ['filter/server-filter-default.vue']
+ },
{
'demoId': 'filter-default-relation',
'name': { 'zh-CN': '输入过滤的默认选项', 'en-US': '' },
diff --git a/packages/vue/src/grid/src/filter/src/methods.ts b/packages/vue/src/grid/src/filter/src/methods.ts
index f2f99b4209..061a628e51 100644
--- a/packages/vue/src/grid/src/filter/src/methods.ts
+++ b/packages/vue/src/grid/src/filter/src/methods.ts
@@ -335,5 +335,8 @@ export default {
this.clearSelection()
return this.updateData()
+ },
+ getAllFilter() {
+ return columnfilters(this.visibleColumn)
}
}
diff --git a/packages/vue/src/grid/src/table/src/methods.ts b/packages/vue/src/grid/src/table/src/methods.ts
index 183e7efe27..008ec73a3b 100644
--- a/packages/vue/src/grid/src/table/src/methods.ts
+++ b/packages/vue/src/grid/src/table/src/methods.ts
@@ -825,6 +825,11 @@ const Methods = {
// 经过动态列个性化合并后,部分列可能被操作隐藏等,此步骤计算可见列
this.refreshColumn()
+ // 可见列刷新后,更新一下表格服务端过滤参数
+ if (this.remoteFilter) {
+ this.$grid.filterData = this.getAllFilter()
+ }
+
// 可见列确定之后触发一次列就绪事件
if (!this.isColumnReady) {
this.isColumnReady = true