找回密码
 立即注册

QQ登录

只需一步,快速开始

Lynn.Dou 讲师达人认证 悬赏达人认证 SpreadJS 开发认证
超级版主   /  发表于:2023-2-28 14:49  /   查看:1557  /  回复:0
背景:

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

0 个回复

您需要登录后才可以回帖 登录 | 立即注册
返回顶部