cloudpivot-sheet-filter 1.0.2 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +61 -38
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -11,32 +11,39 @@
|
|
|
11
11
|
### 通过 CDN 使用
|
|
12
12
|
|
|
13
13
|
#### ES 模块方式
|
|
14
|
+
|
|
14
15
|
```javascript
|
|
15
|
-
|
|
16
|
+
import("https://cdn.jsdelivr.net/npm/cloudpivot-sheet-filter/+esm").then(
|
|
17
|
+
({ default: sheetFilter, FilterOperators }) => {
|
|
18
|
+
// 此处写自己的代码...
|
|
19
|
+
},
|
|
20
|
+
);
|
|
16
21
|
```
|
|
17
22
|
|
|
18
23
|
## 基本使用
|
|
19
24
|
|
|
20
25
|
```javascript
|
|
21
26
|
// 导入模块
|
|
22
|
-
import
|
|
23
|
-
|
|
24
|
-
// 子表筛选定义
|
|
25
|
-
var sheetF = null;
|
|
26
|
-
|
|
27
|
-
// 子表筛选类实例化
|
|
28
|
-
sheetF = new sheetFilter();
|
|
29
|
-
|
|
30
|
-
// 添加筛选条件:检结果等于NG
|
|
31
|
-
// 第一个参数 'Radio1719304490857' 是子表内的控件的编码
|
|
32
|
-
sheetF.addFilter(
|
|
33
|
-
|
|
34
|
-
// 启用筛选
|
|
35
|
-
// 第一个参数 this.Sheet1719303475853 是子表的对象
|
|
36
|
-
sheetF.filter(this.Sheet1719303475853, true);
|
|
37
|
-
|
|
38
|
-
// 关闭筛选
|
|
39
|
-
// sheetF.filter(this.Sheet1719303475853, false);
|
|
27
|
+
import("https://cdn.jsdelivr.net/npm/cloudpivot-sheet-filter/+esm").then(
|
|
28
|
+
({ default: sheetFilter, FilterOperators }) => {
|
|
29
|
+
// 子表筛选定义
|
|
30
|
+
var sheetF = null;
|
|
31
|
+
|
|
32
|
+
// 子表筛选类实例化
|
|
33
|
+
sheetF = new sheetFilter();
|
|
34
|
+
|
|
35
|
+
// 添加筛选条件:检结果等于NG
|
|
36
|
+
// 第一个参数 'Radio1719304490857' 是子表内的控件的编码
|
|
37
|
+
sheetF.addFilter("Radio1719304490857", FilterOperators.EQ, "NG");
|
|
38
|
+
|
|
39
|
+
// 启用筛选
|
|
40
|
+
// 第一个参数 this.Sheet1719303475853 是子表的对象
|
|
41
|
+
sheetF.filter(this.Sheet1719303475853, true);
|
|
42
|
+
|
|
43
|
+
// 关闭筛选
|
|
44
|
+
// sheetF.filter(this.Sheet1719303475853, false);
|
|
45
|
+
},
|
|
46
|
+
);
|
|
40
47
|
```
|
|
41
48
|
|
|
42
49
|
## 高级用法
|
|
@@ -47,7 +54,7 @@ sheetF.filter(this.Sheet1719303475853, true);
|
|
|
47
54
|
|
|
48
55
|
```javascript
|
|
49
56
|
// 添加筛选条件
|
|
50
|
-
sheetF.addFilter(
|
|
57
|
+
sheetF.addFilter("Radio1719304490857", FilterOperators.EQ, "NG");
|
|
51
58
|
|
|
52
59
|
// 预筛选,获取筛选结果但不修改子表
|
|
53
60
|
const previewResult = sheetF.previewFilter(this.Sheet1719303475853);
|
|
@@ -56,7 +63,7 @@ const previewResult = sheetF.previewFilter(this.Sheet1719303475853);
|
|
|
56
63
|
if (previewResult !== null) {
|
|
57
64
|
// 有筛选结果,显示switch开关
|
|
58
65
|
showFilterSwitch(true);
|
|
59
|
-
|
|
66
|
+
|
|
60
67
|
// 用户点击switch开关时应用筛选
|
|
61
68
|
applyFilterButton.onclick = () => {
|
|
62
69
|
sheetF.applyFilter(this.Sheet1719303475853, previewResult);
|
|
@@ -64,7 +71,7 @@ if (previewResult !== null) {
|
|
|
64
71
|
} else {
|
|
65
72
|
// 无筛选结果,隐藏switch开关或禁用
|
|
66
73
|
showFilterSwitch(false);
|
|
67
|
-
alert(
|
|
74
|
+
alert("当前筛选条件无匹配结果,无法进行筛选操作");
|
|
68
75
|
}
|
|
69
76
|
```
|
|
70
77
|
|
|
@@ -74,9 +81,9 @@ if (previewResult !== null) {
|
|
|
74
81
|
// 链式调用添加多个筛选条件
|
|
75
82
|
// 每个 addFilter 的第一个参数都是子表内的控件的编码
|
|
76
83
|
sheetF
|
|
77
|
-
.addFilter(
|
|
78
|
-
.addFilter(
|
|
79
|
-
.addFilter(
|
|
84
|
+
.addFilter("Radio1719304490857", FilterOperators.EQ, "NG") // 控件编码:Radio1719304490857
|
|
85
|
+
.addFilter("Number1719304500123", FilterOperators.GT, 100) // 控件编码:Number1719304500123
|
|
86
|
+
.addFilter("Date1719304510456", FilterOperators.LTE, new Date()); // 控件编码:Date1719304510456
|
|
80
87
|
```
|
|
81
88
|
|
|
82
89
|
### 设置筛选逻辑
|
|
@@ -90,7 +97,7 @@ sheetF.setOrLogic();
|
|
|
90
97
|
|
|
91
98
|
// 获取当前筛选逻辑
|
|
92
99
|
const logic = sheetF.getLogic();
|
|
93
|
-
console.log(
|
|
100
|
+
console.log("当前筛选逻辑:", logic); // 'AND' 或 'OR'
|
|
94
101
|
```
|
|
95
102
|
|
|
96
103
|
### 清除筛选条件
|
|
@@ -105,18 +112,18 @@ sheetF.clearFilters();
|
|
|
105
112
|
```javascript
|
|
106
113
|
// 检查是否已筛选
|
|
107
114
|
const isFiltered = sheetF.isFiltered();
|
|
108
|
-
console.log(
|
|
115
|
+
console.log("是否已筛选:", isFiltered); // true 或 false
|
|
109
116
|
```
|
|
110
117
|
|
|
111
118
|
## 操作符说明
|
|
112
119
|
|
|
113
|
-
| 操作符
|
|
114
|
-
|
|
115
|
-
| FilterOperators.EQ
|
|
116
|
-
| FilterOperators.NEQ | 不等于
|
|
117
|
-
| FilterOperators.LT
|
|
120
|
+
| 操作符 | 描述 | 值 |
|
|
121
|
+
| ------------------- | -------- | ----- |
|
|
122
|
+
| FilterOperators.EQ | 等于 | 'eq' |
|
|
123
|
+
| FilterOperators.NEQ | 不等于 | 'neq' |
|
|
124
|
+
| FilterOperators.LT | 小于 | 'lt' |
|
|
118
125
|
| FilterOperators.LTE | 小于等于 | 'lte' |
|
|
119
|
-
| FilterOperators.GT
|
|
126
|
+
| FilterOperators.GT | 大于 | 'gt' |
|
|
120
127
|
| FilterOperators.GTE | 大于等于 | 'gte' |
|
|
121
128
|
|
|
122
129
|
## API 文档
|
|
@@ -124,6 +131,7 @@ console.log('是否已筛选:', isFiltered); // true 或 false
|
|
|
124
131
|
### sheetFilter 类
|
|
125
132
|
|
|
126
133
|
#### 构造函数
|
|
134
|
+
|
|
127
135
|
```javascript
|
|
128
136
|
const sheetF = new sheetFilter();
|
|
129
137
|
```
|
|
@@ -131,45 +139,60 @@ const sheetF = new sheetFilter();
|
|
|
131
139
|
#### 方法
|
|
132
140
|
|
|
133
141
|
##### setAndLogic()
|
|
142
|
+
|
|
134
143
|
设置筛选逻辑为 AND(默认)。
|
|
135
144
|
|
|
136
145
|
##### setOrLogic()
|
|
146
|
+
|
|
137
147
|
设置筛选逻辑为 OR。
|
|
138
148
|
|
|
139
149
|
##### getLogic()
|
|
150
|
+
|
|
140
151
|
返回当前筛选逻辑,'AND' 或 'OR'。
|
|
141
152
|
|
|
142
153
|
##### isFiltered()
|
|
154
|
+
|
|
143
155
|
返回筛选状态,true 表示已筛选,false 表示未筛选。
|
|
144
156
|
|
|
145
157
|
##### clearFilters()
|
|
158
|
+
|
|
146
159
|
清除所有筛选条件。
|
|
147
160
|
|
|
148
161
|
##### addFilter(columnKey, operator, value)
|
|
162
|
+
|
|
149
163
|
添加筛选条件。
|
|
164
|
+
|
|
150
165
|
- `columnKey`: 子表内的控件的编码(字符串)
|
|
151
166
|
- `operator`: 操作符(字符串或 FilterOperators 常量)
|
|
152
167
|
- `value`: 筛选值(任意类型)
|
|
153
168
|
- 返回值:当前实例,支持链式调用
|
|
154
169
|
|
|
155
170
|
##### filter(key, enable)
|
|
171
|
+
|
|
156
172
|
执行筛选操作。
|
|
173
|
+
|
|
157
174
|
- `key`: 子表的对象
|
|
158
175
|
- `enable`: true 启用筛选,false 关闭筛选
|
|
159
176
|
|
|
160
177
|
##### previewFilter(key)
|
|
178
|
+
|
|
161
179
|
预筛选子表,获取筛选结果但不修改子表对象。
|
|
180
|
+
|
|
162
181
|
- `key`: 子表的对象
|
|
163
182
|
- 返回值:筛选结果 `{ index: [], value: [] }` 或 `null`(无匹配结果)
|
|
164
183
|
|
|
165
184
|
##### applyFilter(key, filteredList)
|
|
185
|
+
|
|
166
186
|
应用筛选,根据预筛选结果修改子表对象。
|
|
187
|
+
|
|
167
188
|
- `key`: 子表的对象
|
|
168
189
|
- `filteredList`: 预筛选结果(可选,如果不提供则自动执行预筛选)
|
|
169
190
|
- 返回值:`true` 成功应用筛选,`false` 筛选失败
|
|
170
191
|
|
|
171
192
|
##### cancelFilter(key)
|
|
193
|
+
|
|
172
194
|
取消筛选,恢复原始子表数据。
|
|
195
|
+
|
|
173
196
|
- `key`: 子表的对象
|
|
174
197
|
- 返回值:`true` 成功取消筛选,`false` 取消失败
|
|
175
198
|
|
|
@@ -177,7 +200,7 @@ const sheetF = new sheetFilter();
|
|
|
177
200
|
|
|
178
201
|
```javascript
|
|
179
202
|
// 导入模块
|
|
180
|
-
import sheetFilter, { FilterOperators } from
|
|
203
|
+
import sheetFilter, { FilterOperators } from "cloudpivot-sheet-filter";
|
|
181
204
|
|
|
182
205
|
// 实例化
|
|
183
206
|
const sheetF = new sheetFilter();
|
|
@@ -188,21 +211,21 @@ sheetF.setOrLogic();
|
|
|
188
211
|
// 添加多个筛选条件
|
|
189
212
|
// 第一个参数都是子表内的控件的编码
|
|
190
213
|
sheetF
|
|
191
|
-
.addFilter(
|
|
192
|
-
.addFilter(
|
|
214
|
+
.addFilter("Radio1719304490857", FilterOperators.EQ, "NG") // 控件编码:Radio1719304490857
|
|
215
|
+
.addFilter("Number1719304500123", FilterOperators.GT, 100); // 控件编码:Number1719304500123
|
|
193
216
|
|
|
194
217
|
// 启用筛选
|
|
195
218
|
// 第一个参数 this.Sheet1719303475853 是子表的对象
|
|
196
219
|
sheetF.filter(this.Sheet1719303475853, true);
|
|
197
220
|
|
|
198
221
|
// 检查筛选状态
|
|
199
|
-
console.log(
|
|
222
|
+
console.log("是否已筛选:", sheetF.isFiltered());
|
|
200
223
|
|
|
201
224
|
// 稍后关闭筛选
|
|
202
225
|
setTimeout(() => {
|
|
203
226
|
// 第一个参数 this.Sheet1719303475853 是子表的对象
|
|
204
227
|
sheetF.filter(this.Sheet1719303475853, false);
|
|
205
|
-
console.log(
|
|
228
|
+
console.log("筛选已关闭");
|
|
206
229
|
}, 5000);
|
|
207
230
|
```
|
|
208
231
|
|