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

🐛 自定义单元格数据不支持下载问题 #2979

Open
4 tasks
liran19960215 opened this issue Nov 15, 2024 · 0 comments
Open
4 tasks

🐛 自定义单元格数据不支持下载问题 #2979

liran19960215 opened this issue Nov 15, 2024 · 0 comments
Labels
next 2.0-next 版本的问题

Comments

@liran19960215
Copy link

🏷 Version

Package Version
@antv/s2 2.0.0-next.32
@antv/s2-react
@antv/s2-vue 2.0.0-next.16

Sheet Type

  • [ √ ] PivotSheet
  • TableSheet
  • GridAnalysisSheet
  • StrategySheet
  • EditableSheet

🖋 Description

先使用自定义层级layoutHierarchy插入了自定义的节点,然后针对自定义的节点使用layoutCellMeta重置渲染数据逻辑,插入的节点渲染时异常,但是在下载时不显示数据,(之前1.x版本是支持的)
image
image

⌨️ Code Snapshots

打开官网链接 https://s2.antv.antgroup.com/examples/react-component/export#export
填充如下代码

// organize-imports-ignore
import React from 'react';
import { S2DataConfig, Node, generateId, EXTRA_FIELD, VALUE_FIELD } from '@antv/s2';
import { SheetComponent, SheetComponentOptions } from '@antv/s2-react';
import '@antv/s2-react/dist/style.min.css';

fetch(
  'https://gw.alipayobjects.com/os/bmw-prod/cd9814d0-6dfa-42a6-8455-5a6bd0ff93ca.json',
)
  .then((res) => res.json())
  .then((res) => {
    const s2Options: SheetComponentOptions = {
      width: 600,
      height: 480,
      interaction: {
        copy: { enable: true },
      },
      layoutHierarchy: (s2, node) => {
        // layoutHierarchy 用于手动控制行列结构的增加、删除的特殊场景。
        // 以 「宁波市」为例,删除其节点,增加宁波A和宁波B节点。
        const { field, value } = node;

        if (field === 'city' && value === '宁波市') {
          const preValue = '宁波A';
          const nextValue = '宁波B';

          const parentNode = node.parent;
          const preUniqueId = generateId(parentNode.id, preValue);
          const nextUniqueId = generateId(parentNode.id, nextValue);
          const preNode = new Node({
            ...node,
            id: preUniqueId,
            value: preValue,
            query: { ...parentNode?.query, [node.field]: preValue },
          });

          const nextNode = new Node({
            ...node,
            id: nextUniqueId,
            value: nextValue,
            query: { ...parentNode?.query, [node.field]: nextValue },
          });

          return {
            push: [nextNode],
            unshift: [preNode],
            delete: true,
          };
        }

        return null;
      },
      layoutCellMeta: (viewMeta) => {
        // 动态改变指定单元格数据, 修订某个或者某些格子的值
        // 下面以更改「浙江省-宁波市-家具-桌子」的单元格数据为例
        const { rowIndex, colIndex } = viewMeta;

        if (rowIndex === 2 || rowIndex === 3) {
          return {
            ...viewMeta,
            data: {
              province: '浙江省',
              city: '宁波市',
              type: '家具',
              sub_type: '桌子',
              number: 99999,
              [EXTRA_FIELD]: 'number',
              [VALUE_FIELD]: 99999,
            },
            fieldValue: 99999,
          };
        }

        return viewMeta;
      },
    };

    const s2DataConfig: S2DataConfig = {
      fields: {
        rows: ['province', 'city'],
        columns: ['type', 'sub_type'],
        values: ['number'],
      },
      meta: res.meta,
      data: res.data,
    };

    reactDOMClient.createRoot(document.getElementById('container')).render(
      <SheetComponent
        dataCfg={s2DataConfig}
        options={s2Options}
        header={{
          export: {
            open: true,
          },
        }}
        adaptive={false}
      />,
    );
  });

🔗 Reproduce Link

https://s2.antv.antgroup.com/examples/react-component/export#export

🤔 Steps to Reproduce

  1. 打开官网链接https://s2.antv.antgroup.com/examples/react-component/export#export
  2. 填充如上代码
  3. 选择“下载格式化数据”
  4. 检验下载内容
    image

😊 Expected Behavior

image
自定义行能正常下载数据

😅 Current Behavior

image
渲染正常 但是下载时缺失数据

💻 System information

Environment Info
System
Browser
@github-actions github-actions bot added the next 2.0-next 版本的问题 label Nov 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
next 2.0-next 版本的问题
Projects
None yet
Development

No branches or pull requests

1 participant