背景:
对一组数据设置筛选后,你会看到一个筛选按钮。点击筛选按钮,会打开筛选框:
筛选框内可以根据筛选需求来对数据进行筛选。
筛选结果如下:
客户需求为,希望在加载数据的时候,即可显示筛选后的结果,所以用代码如何实现呢?
步骤:
- // 赋值
- sheet.setArray(1,1,[[1],[2],[3],[4]]);
- var range = new GC.Spread.Sheets.Range(1, 1, 4, 1);
- // 设置筛选
- var rowFilter = new GC.Spread.Sheets.Filter.HideRowFilter(range);
- sheet.rowFilter(rowFilter);
- //rowFilter.filterButtonVisible(false);
- // 根据需求设置相应的筛选条件
- var condition1 = new GC.Spread.Sheets.ConditionalFormatting.Condition(GC.Spread.Sheets.ConditionalFormatting.ConditionType.cellValueCondition, {compareType: GC.Spread.Sheets.ConditionalFormatting.TextCompareType.equalsTo, expected: 1});
- var condition2 = new GC.Spread.Sheets.ConditionalFormatting.Condition(GC.Spread.Sheets.ConditionalFormatting.ConditionType.cellValueCondition, {compareType: GC.Spread.Sheets.ConditionalFormatting.TextCompareType.equalsTo, expected: 2});
- var condition3 = new GC.Spread.Sheets.ConditionalFormatting.Condition(GC.Spread.Sheets.ConditionalFormatting.ConditionType.cellValueCondition, {compareType: GC.Spread.Sheets.ConditionalFormatting.TextCompareType.equalsTo, expected: 3});
- // 将筛选条件添加到filter中
- rowFilter.addFilterItem(1, condition1);
- rowFilter.addFilterItem(1, condition2);
- rowFilter.addFilterItem(1, condition3);
- rowFilter.filter(1);
复制代码 效果如下:
|
|