Code Monkey home page Code Monkey logo

Comments (8)

lijinke666 avatar lijinke666 commented on September 18, 2024

demo 打不开

from s2.

voidman2017 avatar voidman2017 commented on September 18, 2024

demo 打不开

import { PivotSheet, BaseEvent, S2Event } from "@antv/s2";

class ContextMenu extends BaseEvent {
bindEvents() {
this.spreadsheet.on(S2Event.DATA_CELL_CONTEXT_MENU, (event) => {
{
console.log("右键点击了单元格", event);
const cell = this.spreadsheet.getCell(event.target);
const meta = cell.getMeta();
console.log("===debug=== meta: ", meta);
console.log("cell", cell);
}

  {
    // 首先拿到单元格当前信息
    const cell = this.spreadsheet.getCell(event.target);
    const meta = cell.getMeta();

    // 获取当前行数据
    const rowData = this.spreadsheet.dataSet.getCellData({
      query: meta.query,
    });
    // 获取当前行头单元格数据:
    const rowCellData = this.spreadsheet.dataSet.getCellData({
      query: meta.query,
    });
    // 获取当前行头维值
    const dimensionValues = this.spreadsheet.dataSet.getDimensionValues(
      meta.field
    );

    console.log("当前行数据:", rowData);
    console.log("当前行头单元格数据:", rowCellData);
    console.log("当前行头维值:", dimensionValues);
  }
});

this.spreadsheet
  .getCanvasElement()
  .addEventListener("contextmenu", (event) => {
    // 禁止弹出右键菜单
    event.preventDefault();
  });

}
}

fetch(
"https://gw.alipayobjects.com/os/bmw-prod/2a5dbbc8-d0a7-4d02-b7c9-34f6ca63cff6.json"
)
.then((res) => res.json())
.then((dataCfg) => {
const container = document.getElementById("container");

const s2Options = {
  width: 600,
  height: 480,
  style: {
    // 了解更多: https://s2.antv.antgroup.com/api/general/s2-options#style
    layoutWidthType: "adaptive",
  },
  interaction: {
    customInteractions: [
      {
        key: "ContextMenu",
        interaction: ContextMenu,
      },
    ],
  },
};
const s2 = new PivotSheet(container, dataCfg, s2Options);

s2.render();

});
示例代码如上

from s2.

lijinke666 avatar lijinke666 commented on September 18, 2024

用的什么版本, issue 请按照模版填写, 下次直接关闭了

from s2.

voidman2017 avatar voidman2017 commented on September 18, 2024

用的什么版本, issue 请按照模版填写, 下次直接关闭了

👌
看了下使用的是1.55.7版本

from s2.

lijinke666 avatar lijinke666 commented on September 18, 2024

1.x 的文档不太全.

  1. 你监听的是 dataCell 的右键, 你想获取对应的当前行, 本质上就是获取当前行头的数据, 所以是获取一组数据 (getMultiData) 而不是单个数据 (getCellData), 用 meta.rowQuery 查询就好了. 同理, 当前列就用 colQuery
class ContextMenu extends BaseEvent {
  bindEvents() {
    this.spreadsheet.on(S2Event.DATA_CELL_CONTEXT_MENU, (event) => {
      {
        const cell = this.spreadsheet.getCell(event.target);
        const meta = cell?.getMeta();

        // 获取当前行数据
        const rowData = this.spreadsheet.dataSet.getMultiData(meta?.rowQuery);

      }
    });
  }
}
  1. 粘贴代码请遵循基本的 markdown 格式.
  2. 使用问题请直接在讨论区 https://github.com/antvis/S2/discussions/categories/q-a 提问

from s2.

github-actions avatar github-actions commented on September 18, 2024

你好 @voidman2017, Issue 板块是用于 bug 反馈与需求讨论的地方。你可以试着在 antv s2 discussions 新开一个 discussion, 选择 🙏Q&A 类别进行提问, 我们会及时进行解答, 感谢你的理解。

Hello, @voidman2017. The Issue section is used for bug feedback and requirement discussion. You could open a new discussion in antv s2 discussions, choose the 🙏Q&A category to ask questions. We will answer in time. Thanks so much for your understanding.

from s2.

voidman2017 avatar voidman2017 commented on September 18, 2024

1.x 的文档不太全.

  1. 你监听的是 dataCell 的右键, 你想获取对应的当前行, 本质上就是获取当前行头的数据, 所以是获取一组数据 (getMultiData) 而不是单个数据 (getCellData), 用 meta.rowQuery 查询就好了. 同理, 当前列就用 colQuery
class ContextMenu extends BaseEvent {
  bindEvents() {
    this.spreadsheet.on(S2Event.DATA_CELL_CONTEXT_MENU, (event) => {
      {
        const cell = this.spreadsheet.getCell(event.target);
        const meta = cell?.getMeta();

        // 获取当前行数据
        const rowData = this.spreadsheet.dataSet.getMultiData(meta?.rowQuery);

      }
    });
  }
}
  1. 粘贴代码请遵循基本的 markdown 格式.
  2. 使用问题请直接在讨论区 https://github.com/antvis/S2/discussions/categories/q-a 提问

那如果是TableSheet是否无法实现该功能

from s2.

lijinke666 avatar lijinke666 commented on September 18, 2024

image

文档有写, 请认真阅读, 明细表一行就是一条数据, 根据 rowIndex 去查, 两者等价:

image

from s2.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.