You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过Tableau扩展API清除仪表盘分类筛选器值?

清除Tableau仪表盘中所有分类筛选器的解决方法

要清除所有分类筛选器,你可以利用Tableau扩展API中CategoricalFilter接口的applyFilterAsync方法,通过设置筛选类型为All来重置筛选器,恢复显示所有数据。具体实现如下:

完整代码示例

const dashboard = tableau.extensions.dashboardContent.dashboard;

dashboard.getFiltersAsync().then((filters) => {
  // 遍历所有筛选器
  filters.forEach(async (filter) => {
    // 判断当前筛选器是否为分类筛选器
    if (filter.filterType === tableau.FilterType.Categorical) {
      // 转换为CategoricalFilter类型以调用对应方法
      const categoricalFilter = filter as tableau.CategoricalFilter;
      // 应用"显示全部"的筛选规则,清除已选值
      await categoricalFilter.applyFilterAsync(
        [],
        tableau.FilterType.All
      );
    }
  });
});

关键说明

  • 筛选器类型判断:仪表盘中可能存在范围型(Range)等其他类型的筛选器,只有分类筛选器(Categorical)适用此方法,所以需要先做类型校验。
  • applyFilterAsync方法逻辑:第一个参数传空数组,第二个参数指定tableau.FilterType.All,这会让Tableau清除当前筛选器的所有选中值,展示该字段的全部数据。
  • 官方文档中CategoricalFilter接口的applyFilterAsync支持三种筛选模式:
    • All:显示所有数据,即清除筛选
    • SingleValue:单选单个值
    • MultipleValues:多选多个值

替代技巧(版本兼容备用方案)

如果上述方法因API版本兼容问题无法生效,可以尝试间接触发Tableau内置动作:

  1. 在Tableau桌面端给目标筛选器创建「清除筛选器」的动作
  2. 在扩展中通过dashboard.findSheetAsync(sheetName)找到对应工作表,再调用performActionAsync(actionName)触发该动作

内容的提问来源于stack exchange,提问作者Matt

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.20 01:44:59