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

🐛Node.belongsCell不能同步获取,需使用异步方式才可以获取 #2803

Closed
1 task done
EthanLiBin opened this issue Jul 3, 2024 · 1 comment
Closed
1 task done
Assignees
Labels
next 2.0-next 版本的问题

Comments

@EthanLiBin
Copy link

EthanLiBin commented Jul 3, 2024

🏷 Version

Package Version
@antv/s2 2.0.0-next.23

Sheet Type

  • PivotSheet

🖋 Description

Node.belongsCell不能同步获取,需使用异步方式才可以获取
Node.belongsCell目前使用setTimeout包裹或者 await 实现的sleep后 才能拿到。

⌨️ Code Snapshots

🔗 Reproduce Link

🤔 Steps to Reproduce

const s2Options: S2Options = {
style: {
colCell: cellTextWordWrapStyle,
},
}

const cellTextWordWrapStyle: CellTextWordWrapStyle = {
height: (colNode) => {
return 40;
},
heightByField: {
[EXTRA_FIELD]: 45,
},
width: async (rowNode) => {
// rowNode.belongsCell 同步时为undefind
setTimeout(() => {
rowNode.belongsCell.getActualText()
}, 0)
},
// 最大行数,文本超出后将被截断
maxLines: 2,
// 文本是否换行
wordWrap: true,
textOverflow: 'ellipsis',
};

😊 Expected Behavior

rowNode.belongsCell同步状态应该可以获取到cell

😅 Current Behavior

💻 System information

Environment Info
System
Browser
@github-actions github-actions bot added the next 2.0-next 版本的问题 label Jul 3, 2024
@lijinke666
Copy link
Member

lijinke666 commented Jul 3, 2024

布局的流程是 node => cell => layout

width: async (rowNode) => 这个 hook 调用的时候是在生成 node 的阶段, 请注意, 注入的参数是 rowNode, 而不是 rowCell, 是用于更改 node 的宽高, 此时还没有生成 cell, 获取不到是符合预期的, 这个和异步没关系.

你没有描述你具体用来做什么, 看起来是根据渲染的文本来调整宽度

你可以在 s2.render 之后拿到单元格信息, 然后再根据你自己的诉求更新 style

const colCell = s2.facet.getColCells()[0]
const text = colCell.getActualText()

...你自己的逻辑

s2.setOptions({
  style: {
    colCell: {
      width: 宽度,
    },
  },
});
s2.render(false)

PS: 粘贴代码请使用基本的 markdown 格式, 强迫症有点难受

@lijinke666 lijinke666 self-assigned this Jul 3, 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

2 participants