• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.arkui.advanced.Filter(多条件筛选)
2
3
4多条件筛选,帮助用户在大量信息中找到所需内容,应结合具体场景选择合适筛选方式。多条件筛选控件由筛选器与悬浮条构成,悬浮条可下拉展示悬浮筛选器。筛选器样式可分为多行可折叠类型与多行列表类型,并可以在筛选器最后一行附加快捷筛选器。
5
6
7> **说明:**
8>
9> 该组件从API Version 10开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。
10
11
12## 导入模块
13
14```
15import { Filter } from '@ohos.arkui.advanced.Filter'
16```
17
18
19## 子组件
20
2122
23## 属性
24支持[通用属性](ts-universal-attributes-size.md)
25
26## Filter
27
28Filter({ multiFilters: Array<FilterParams>,  additionFilters: FilterParams, filterType: FilterType, onFilterChanged: (Array<FilterResult>) => void, container: ()=> void })
29
30**装饰器类型:**\@Component
31
32**系统能力:** SystemCapability.ArkUI.ArkUI.Full
33
34**参数:**
35
36
37| 名称 | 参数类型 | 必填  | 装饰器类型 | 说明 |
38| -------- | -------- | -------- | -------- | -------- |
39| multiFilters | Array<[FilterParams](#filterparams)> | 是   | \@Prop | 多条件筛选列表。 |
40| additionFilters | [FilterParams](#filterparams) | 否   | \@Prop | 附加快捷筛选项。 |
41| filterType | [FilterType](#filtertype) | 否   | \@Prop | 筛选器的样式类型。 |
42| onFilterChanged | (Array<[FilterResult](#filterresult)>) => void | 是   | - | 用户点击后的回调事件。回调函数的参数为选中的筛选项结果列表。 |
43| container | ()=>void | 是   | \@BuilderParam | 筛选结果展示区域自定义内容,通过尾随闭包形式传入。 |
44
45
46## FilterParams
47
48| 名称 | 类型 | 必填 | 说明 |
49| -------- | -------- | -------- | -------- |
50| name | [ResourceStr](ts-types.md#resourcestr) | 是 | 筛选项维度名称。 |
51| options | Array<[ResourceStr](ts-types.md#resourcestr)> | 是 | 筛选项维度可选项列表。 |
52
53
54## FilterType
55
56| 名称 | 值 | 说明 |
57| -------- | -------- | -------- |
58| MULTI_LINE_FILTER | 0 | 多行可折叠类型筛选器。 |
59| LIST_FILTER | 1 | 多行列表类型筛选器。 |
60
61
62## FilterResult
63
64| 名称 | 类型 | 必填 | 说明 |
65| -------- | -------- | -------- | -------- |
66| name | [ResourceStr](ts-types.md#resourcestr) | 是 | 筛选项维度名称。 |
67| index | number | 是 | 该维度筛选项选中项目的索引值。 |
68| value | [ResourceStr](ts-types.md#resourcestr) | 是 | 该维度筛选项选中项目的值。 |
69
70## 事件
71不支持[通用事件](ts-universal-events-click.md)
72
73## 示例
74
75```ts
76import { Filter, FilterParams, FilterResult, FilterType } from '@ohos.arkui.advanced.Filter'
77
78@Entry
79@Component
80struct Index {
81  private filterParam: Array<FilterParams> = [{name: '月份', options: ['全部','1月','2月','3月','4月','5月','6月','7月','8月','9月','10月','11月','12月']},
82    {name: '年份', options: ['全部','2023','2022','2021','2020','2019','2018','2017','2016','2015','2014','2013','2012','2011','2010','2009','2008']},
83    {name: '节气', options: ['全部','立春','雨水','惊蛰','春分','清明','谷雨','立夏','小满','芒种','夏至','小暑','大暑','立秋','处暑','白露','秋分','寒露','霜降','立冬','小雪','大雪','冬至','小寒','大寒']}]
84  private additionParam: FilterParams = { name: '您还可以搜', options: ['运营栏目1','运营栏目2','运营栏目3','运营栏目4','运营栏目5','运营栏目6']}
85  private arr: number[] = [1,2,3,4,5,6,7,8,9,10,1,2,3,4,5,6,7,8,9,10];
86  build() {
87    Column() {
88      Filter({
89        multiFilters: this.filterParam,
90        additionFilters: this.additionParam,
91        filterType: FilterType.MULTI_LINE_FILTER,
92        onFilterChanged: (select: Array<FilterResult>) => {
93          console.log('rec filter change')
94          for (let filter of select) {
95            console.log('name:' + filter.name + ',index:' + filter.index + ',value:' + filter.value)
96          }
97        }
98      }){
99        List({ initialIndex: 0 }) {
100          ForEach(this.arr, (item:string, index: number) => {
101            ListItem() {
102              Text(item.toString())
103                .width("100%")
104                .height(100)
105                .fontSize(16)
106                .textAlign(TextAlign.Center)
107                .borderRadius(10)
108                .backgroundColor(Color.White)
109                .margin({ top:10, bottom: 10 })
110            }
111          })
112        }.backgroundColor(Color.Gray)
113        .padding({ left: 20, right: 20 })
114      }
115    }
116    .height('100%')
117    .width('100%')
118  }
119}
120```
121
122![zh-cn_image_0000001665809293](figures/zh-cn_image_0000001665809293.png)
123