8000 feat: add batch expand/collapse all tree nodes by PoorShawn · Pull Request #4033 · VisActor/VTable · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat: add batch expand/collapse all tree nodes #4033

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

Merged

Conversation

PoorShawn
Copy link
Contributor

[中文版模板 / Chinese template]

🤔 This is a ...

  • New feature
  • Bug fix
  • TypeScript definition update
  • Bundle size optimization
  • Performance optimization
  • Enhancement feature
  • Refactoring
  • Update dependency
  • Code style optimization
  • Test Case
  • Branch merge
  • Site / documentation update
  • Demo update
  • Workflow
  • Chore
  • Release
  • Other (about what?)

🔗 Related issue link

relate #3078

💡 Background and solution

实现方案:

增强底层数据层:在 DataSource 中增加了 expandAllNodes() 和 collapseAllNodes() 方法,通过递归遍历数据源,统一设置所有节点的 hierarchyState 属性,并重建表格的层级状态。

基于数据层增加 API :在 ListTable 中新增了两个公共 API:expandAllTreeNode() 和 collapseAllTreeNode()。这两个方法会同步更新表头和数据行的节点状态,然后刷新整个表格视图,并触发相应的 TREE_HIERARCHY_STATE_CHANGE 事件。

功能演示:

screenshot_2025-06-12_22-50-36

新增 API 及使用示例:

// 展开所有树形节点(包括表头和数据行)
tableInstance.expandAllTreeNode(): void;

// 折叠所有树形节点(包括表头和数据行)
tableInstance.collapseAllTreeNode(): void;

📝 Changelog

Language Changelog
🇺🇸 English Added expandAllTreeNode() and collapseAllTreeNode() methods to support batch expanding and collapsing of all tree nodes for ListTable.
🇨🇳 Chinese 针对 ListTable,新增 expandAllTreeNode() 和 collapseAllTreeNode()方法,支持批 8000 展开和折叠所有树形节点。

☑️ Self-Check before Merge

⚠️ Please check all items below before requesting a reviewing. ⚠️

  • Doc is updated/provided or not needed
  • Demo is updated/provided or not needed
  • TypeScript definition is updated/provided or not needed
  • Changelog is provided or not needed

🚀 Summary

copilot:summary

🔍 Walkthrough

copilot:walkthrough


// 刷新视图
if (stateChanged) {
this.updateColumns(this.internalProps.columns); // 应用表头变化并重新评估列
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里的逻辑有点奇怪 可以看看有没有其他更好的逻辑

Copy link
Contributor Author
@PoorShawn PoorShawn Jun 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

是的,感谢指出!updateColumns 应该是一个开销比较大的操作,这里会造成性能的浪费,是一个可以优化的点

@PoorShawn
Copy link
Contributor Author
PoorShawn commented Jun 15, 2025

@fangsmile 我增加和使用了 _recreateSceneForStateChange,作为 updateColumns 的轻量级替代方案,避免了 updateColumns 中开销较大的 cloneDeepSpec 深拷贝操作

@Rui-Sun
Copy link
Contributor
Rui-Sun commented Jun 16, 2025

看起来还是有问题,可以试一下这个示例

const option = {
    rows: ['province', 'city'],
    columns: ['category', 'sub_category'],
    indicators: ['sales', 'number'],
    enableDataAnalysis: true,
    indicatorTitle: '指标名称',
    indicatorsAsCol: false,
    corner: { titleOnDimension: 'row' },
    records: [
      {
        sales: 891,
        number: 7789,
        province: '浙江省',
        city: '杭州市',
        category: '家具',
        sub_category: '桌子'
      },
      {
        sales: 792,
        number: 2367,
        province: '浙江省',
        city: '绍兴市',
        category: '家具',
        sub_category: '桌子'
      },
      {
        sales: 893,
        number: 3877,
        province: '浙江省',
        city: '宁波市',
        category: '家具',
        sub_category: '桌子'
      },
      {
        sales: 1094,
        number: 4342,
        province: '浙江省',
        city: '舟山市',
        category: '家具',
        sub_category: '桌子'
      },
      {
        sales: 1295,
        number: 5343,
        province: '浙江省',
        city: '杭州市',
        category: '家具',
        sub_category: '沙发'
      },
      {
        sales: 496,
        number: 632,
        province: '浙江省',
        city: '绍兴市',
        category: '家具',
        sub_category: '沙发'
      },
      {
        sales: 1097,
        number: 7234,
        province: '浙江省',
        city: '宁波市',
        category: '家具',
        sub_category: '沙发'
      },
      {
        sales: 998,
        number: 834,
        province: '浙江省',
        city: '舟山市',
        category: '家具',
        sub_category: '沙发'
      },
      {
        sales: 766,
        number: 945,
        province: '浙江省',
        city: '杭州市',
        category: '办公用品',
        sub_category: '笔'
      },
      {
        sales: 990,
        number: 1304,
        province: '浙江省',
        city: '绍兴市',
        category: '办公用品',
        sub_category: '笔'
      },
      {
        sales: 891,
        number: 1145,
        province: '浙江省',
        city: '宁波市',
        category: '办公用品',
        sub_category: '笔'
      },
      {
        sales: 792,
        number: 1432,
        province: '浙江省',
        city: '舟山市',
        category: '办公用品',
        sub_category: '笔'
      },
      {
        sales: 745,
        number: 1343,
        province: '浙江省',
        city: '杭州市',
        category: '办公用品',
        sub_category: '纸张'
      },
      {
        sales: 843,
        number: 1354,
        province: '浙江省',
        city: '绍兴市',
        category: '办公用品',
        sub_category: '纸张'
      },
      {
        sales: 895,
        number: 1523,
        province: '浙江省',
        city: '宁波市',
        category: '办公用品',
        sub_category: '纸张'
      },
      {
        sales: 965,
        number: 1634,
        province: '浙江省',
        city: '舟山市',
        category: '办公用品',
        sub_category: '纸张'
      },
      {
        sales: 776,
        number: 1723,
        province: '四川省',
        city: '成都市',
        category: '家具',
        sub_category: '桌子'
      },
      {
        sales: 634,
        number: 1822,
        province: '四川省',
        city: '绵阳市',
        category: '家具',
        sub_category: '桌子'
      },
      {
        sales: 909,
        number: 1943,
        province: '四川省',
        city: '南充市',
        category: '家具',
        sub_category: '桌子'
      },
      {
        sales: 399,
        number: 2330,
        province: '四川省',
        city: '乐山市',
        category: '家具',
        sub_category: '桌子'
      },
      {
        sales: 700,
        number: 2451,
        province: '四川省',
        city: '成都市',
        category: '家具',
        sub_category: '沙发'
      },
      {
        sales: 689,
        number: 2244,
        province: '四川省',
        city: '绵阳市',
        category: '家具',
        sub_category: '沙发'
      },
      {
        sales: 500,
        number: 2333,
        province: '四川省',
        city: '南充市',
        category: '家具',
        sub_category: '沙发'
      },
      {
        sales: 800,
        number: 2445,
        province: '四川省',
        city: '乐山市',
        category: '家具',
        sub_category: '沙发'
      },
      {
        sales: 1044,
        number: 2335,
        province: '四川省',
        city: '成都市',
        category: '办公用品',
        sub_category: '笔'
      },
      {
        sales: 689,
        number: 245,
        province: '四川省',
        city: '绵阳市',
        category: '办公用品',
        sub_category: '笔'
      },
      {
        sales: 794,
        number: 2457,
        province: '四川省',
        city: '南充市',
        category: '办公用品',
        sub_category: '笔'
      },
      {
        sales: 566,
        number: 2458,
        province: '四川省',
        city: '乐山市',
        category: '办公用品',
        sub_category: '笔'
      },
      {
        sales: 865,
        number: 4004,
        province: '四川省',
        city: '成都市',
        category: '办公用品',
        sub_category: '纸张'
      },
      {
        sales: 999,
        number: 3077,
        province: '四川省',
        city: '绵阳市',
        category: '办公用品',
        sub_category: '纸张'
      },
      {
        sales: 999,
        number: 3551,
        province: '四川省',
        city: '南充市',
        category: '办公用品',
        sub_category: '纸张'
      },
      {
        sales: 999,
        number: 352,
        province: '四川省',
        city: '乐山市',
        category: '办公用品',
        sub_category: '纸张'
      }
    ],
rowSeriesNumber: {
      enable: true,
      title: '',
      field: 'name',
      dragOrder: true,
      // headerIcon: 'book',
      width: 'auto',
      // format: (args: any) => {
      //   return '';
      // },
      headerStyle: {
        color: 'black',
        bgColor: 'pink'
      },
      style: {
        color: 'red'
      }
    },
dragHeaderMode:'all',
    widthMode: 'autoWidth' // 宽度模式:standard 标准模式; adaptive 自动填满容器
  };

@PoorShawn
Copy link
Contributor Author

感谢耐心的测试!我注意到这是一段 PivotTable 透视表的配置。关于节点一次性展开/折叠全部节点的能力,目前只针对 ListTable 进行了处理。关于 PivotTable 透视表的处理,我还在进行相应的修改

@PoorShawn
Copy link
Contributor Author

@Rui-Sun 关于透视表节点的一键展开/折叠,也进行了相应的支持,请求再次审核

col: -1,
row: -1,
hierarchyState: HierarchyState.collapse,
originData: this.internalProps.layoutMap.columnDimensionTree.tree
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

触发事件的这个originData可以去掉。事件定义中加个明确的参数changeAll:boolean

expandAllTreeNode(): void {
let stateChanged = false;

// 展开所有表头节点
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

把这块逻辑先去掉吧 后续有需求可以单独开个header的接口

/**
* 展开所有树形节点
*/
expandAllTreeNode(): void {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

执行逻辑前最好有个判断,可以调用这个 看用户是否是tree模式下
image

/**
* 展开行表头树的所有节点
*/
expandAllForRowTree() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个也一样先判断是否是tree模式 columnHierarchyType rowHierarchyType

  /**层级维度结构显示形式 */
  rowHierarchyType?: 'grid' | 'tree' | 'grid-tree';
  columnHierarchyType?: 'grid' | 'grid-tree';

记得测试下 'tree' | 'grid-tree'

@PoorShawn
Copy link
Contributor Author

嗯嗯好的,已经完成了相应的修改,'tree' | 'grid-tree' 在 demo 上的测试也是 ok 的

8000

@fangsmile fangsmile changed the base branch from develop to feat/add_batch_expand_collapse_api July 7, 2025 06:32
@fangsmile fangsmile merged commit 8aa0002 into VisActor:feat/add_batch_expand_collapse_api Jul 7, 2025
3 of 4 checks passed
@fangsmile fangsmile mentioned this pull request Jul 7, 2025
21 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0