Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛小计总计功能 自定义总计函数(calcFunc)中无小计汇总信息 #2795

Closed
1 of 5 tasks
chen610620 opened this issue Jun 27, 2024 · 6 comments · Fixed by #2805
Closed
1 of 5 tasks

🐛小计总计功能 自定义总计函数(calcFunc)中无小计汇总信息 #2795

chen610620 opened this issue Jun 27, 2024 · 6 comments · Fixed by #2805
Assignees
Labels

Comments

@chen610620
Copy link

🏷 Version

Package Version
@antv/s2 1.55.0
@antv/s2-react 1.47.0
@antv/s2-vue

Sheet Type

  • PivotSheet
  • TableSheet
  • GridAnalysisSheet
  • StrategySheet
  • EditableSheet

🖋 Description

小计总计功能 自定义总计函数(calcFunc)中无小计汇总信息。 仅有最小单元数据。
原有使用 s2: 1.47.1, s2-react: 1.40.0中, 自定义汇总函数的第二个入参 包含单元格数据+小计汇总数据。
升级到最新版本(1.55.0)后,自定义汇总函数的第二个入参, 仅包含单元格数据。

存在差异情况

⌨️ Code Snapshots

bug重现可使用官网demo修改配置进行复现:

官网示例
js配置修改如下

import { PivotSheet } from '@antv/s2';

fetch(
  'https://gw.alipayobjects.com/os/bmw-prod/4347c2dd-6554-451b-9d44-15b04e5de657.json',
)
  .then((res) => res.json())
  .then((data) => {
    const container = document.getElementById('container');
    const s2DataConfig = {
      fields: {
        rows: ['province', 'city'],
        columns: ['type'],
        values: ['price'],
      },
      meta: [
        {
          field: 'province',
          name: '省份',
        },
        {
          field: 'city',
          name: '城市',
        },
        {
          field: 'type',
          name: '商品类别',
        },
        {
          field: 'price',
          name: '价格',
        },
      ],
      data: data.filter(function (a) {
        return Object.keys(a).length>2;
      }),
    };

    const s2Options = {
      width: 600,
      height: 480,
      hierarchyType: 'tree',
      tooltip: {
        showTooltip: true,
      },
      interaction: {
        enableCopy: true,
        selectedCellsSpotlight: true,
        hoverHighlight: true,
      },
      totals: {
        row: { 
          showGrandTotals: true,
          showSubTotals: true,
          // reverseLayout: true,
        
          // subTotalsDimensions: ['province'],
            calcTotals: {
            calcFunc: function (a, arr) {
              console.log("bb", arr)
              return 15;
            },
          },
        },
        col: {
          showGrandTotals: true,
          showSubTotals: true,
          // reverseLayout: true,
          // reverseSubLayout: true,
          // subTotalsDimensions: ['type'],
          calcTotals: {
            calcFunc: function (a, arr) {
              console.log("aa", arr)
              return 10;
            },
          },
        },
      },
    };
    const s2 = new PivotSheet(container, s2DataConfig, s2Options);

    s2.render();
  });

🤔 Steps to Reproduce

无操作步骤, 仅打开调试控制台即可

😊 Expected Behavior

预期行为:控制台输出应包含小计数据, eg:

  {
    "type": "",
    "province": "浙江",
    "price": "3"
  },

😅 Current Behavior

当前仅包含单元格数据

💻 System information

Environment Info
System window 10
Browser 126.0.6478.127
@lijinke666 lijinke666 assigned lijinke666 and wjgogogo and unassigned lijinke666 Jun 28, 2024
@lijinke666
Copy link
Member

@wjgogogo 看一下

@lijinke666
Copy link
Member

lijinke666 commented Jul 3, 2024

calcFunc 无汇总数据是有意为之, 自定义汇总本质上是对明细数据进行汇总, 如果汇总数据混入其中的话会导致数据二次累加, 会导致 BUG, 如果你希望获取全部的数据, 可以根据 query 主动查询一次, 代替第二个参数 (ps: 什么情况需要获取汇总数据, 理论上不需要才对吧).

import { QueryDataType } from '@antv/s2';

calcFunc(query) {
+  const allData = s2.dataSet.getMultiData(query, {
+    queryType: QueryDataType.All,
+  });
  console.log(allData);
  return 15;
},

这里可能无法拿到 s2 实例, 近期我们增加第三个参数好了, 更灵活一点

@chen610620
Copy link
Author

ok, 好的。那我就主动查询一次解决问题。

1 similar comment
@chen610620
Copy link
Author

ok, 好的。那我就主动查询一次解决问题。

@lijinke666 lijinke666 assigned lijinke666 and unassigned wjgogogo Jul 4, 2024
lijinke666 added a commit that referenced this issue Jul 5, 2024
* fix: 自定义计算汇总 calcFunc 回调函数增加 s2 实例, 修复无法获取汇总数据的问题 close #2795

* docs: 更新文档主题版本

* docs: 更新文档主题版本
@lijinke666
Copy link
Member

🎉 This issue has been resolved in version @antv/s2-v1.55.7 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
3 participants