Skip to content

Commit

Permalink
Merge pull request #840 from VisActor/839-feature-api-getcellheadertr…
Browse files Browse the repository at this point in the history
…eenodes-pivottable

839 feature api getcellheadertreenodes pivottable
  • Loading branch information
fangsmile authored Jan 3, 2024
2 parents d1d270f + 1385cd3 commit eb0e650
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"changes": [
{
"comment": "feat: add api getCellHeaderTreeNodes for pivotTable #839\n\n",
"type": "none",
"packageName": "@visactor/vtable"
}
],
"packageName": "@visactor/vtable",
"email": "[email protected]"
}
23 changes: 19 additions & 4 deletions docs/assets/api/en/methods.md
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,21 @@ Get the path to the row list header

{{ use: ICellHeaderPaths() }}


## getCellHeaderTreeNodes(Function)

Obtain the header tree node based on the row and column number, which includes the user's custom attributes on the custom tree rowTree and columnTree trees (it is also the node of the internal layout tree, please do not modify it at will after obtaining it).Under normal circumstances, just use getCellHeaderPaths.

```
/**
* Obtain the header tree node based on the row and column number, which includes the user's custom attributes on the custom tree rowTree and columnTree trees (it is also the node of the internal layout tree, please do not modify it at will after obtaining it)
* @param col
* @param row
* @returns ICellHeaderPaths
*/
getCellHeaderTreeNodes(col: number, row: number)=> ICellHeaderPaths
```

## getCellAddress(Function)

Get the row and column number of a piece of data in the body based on the data and field attribute field names. Currently only the basic table ListTable is supported.
Expand Down Expand Up @@ -513,7 +528,7 @@ enum HierarchyState {
none = 'none'
}
```
## getLayouRowTree(Function)
## getLayoutRowTree(Function)
** PivotTable Proprietary **

Get the table row header tree structure
Expand All @@ -522,10 +537,10 @@ Get the table row header tree structure
* Get the table row tree structure
* @returns
*/
getLayouRowTree() : LayoutTreeNode[]
getLayoutRowTree() : LayoutTreeNode[]
```

## getLayouRowTreeCount(Function)
## getLayoutRowTreeCount(Function)
** PivotTable Proprietary **

Get the total number of nodes occupying the table row header tree structure.
Expand All @@ -536,7 +551,7 @@ Note: The logic distinguishes between flat and tree hierarchies.
* Get the total number of nodes occupying the table row header tree structure.
* @returns
*/
getLayouRowTreeCount() : number
getLayoutRowTreeCount() : number
```

## updateSortState(Function)
Expand Down
22 changes: 18 additions & 4 deletions docs/assets/api/zh/methods.md
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,20 @@ setRecords(records: Array<any>, sort?: SortState | SortState[]) //** 基本表

{{ use: ICellHeaderPaths() }}

## getCellHeaderTreeNodes(Function)

根据行列号获取表头tree节点,包含了用户在自定义树rowTree及columnTree树上的自定义属性(也是内部布局树的节点,获取后请不要随意修改)。一般情况下用getCellHeaderPaths即可。

```
/**
* 根据行列号获取表头tree节点,包含了用户在自定义树rowTree及columnTree树上的自定义属性(也是内部布局树的节点,获取后请不要随意修改)
* @param col
* @param row
* @returns ICellHeaderPaths
*/
getCellHeaderTreeNodes(col: number, row: number)=> ICellHeaderPaths
```

## getCellAddress(Function)

根据数据和 field 属性字段名称获取 body 中某条数据的行列号。目前仅支持基本表格ListTable
Expand Down Expand Up @@ -507,7 +521,7 @@ enum HierarchyState {
}
```

## getLayouRowTree(Function)
## getLayoutRowTree(Function)
** PivotTable 专有 **

获取表格行头树形结构
Expand All @@ -516,10 +530,10 @@ enum HierarchyState {
* 获取表格行树状结构
* @returns
*/
getLayouRowTree() : LayouTreeNode[]
getLayoutRowTree() : LayouTreeNode[]
```

## getLayouRowTreeCount(Function)
## getLayoutRowTreeCount(Function)
** PivotTable 专有 **

获取表格行头树形结构的占位的总节点数。
Expand All @@ -530,7 +544,7 @@ enum HierarchyState {
* 获取表格行头树形结构的占位的总节点数。
* @returns
*/
getLayouRowTreeCount() : number
getLayoutRowTreeCount() : number
```

## updateSortState(Function)
Expand Down
11 changes: 11 additions & 0 deletions packages/vtable/src/PivotTable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -933,6 +933,17 @@ export class PivotTable extends BaseTable implements PivotTableAPI {
const layoutMap = this.internalProps.layoutMap;
return layoutMap.getLayoutRowTreeCount();
}
/**
* 根据行列号获取表头tree节点,包含了用户在自定义树rowTree及columnTree树上的自定义属性(也是内部布局树的节点,获取后请不要随意修改)
* @param col
* @param row
* @returns
*/
getCellHeaderTreeNodes(col: number, row: number): ICellHeaderPaths {
const layoutMap = this.internalProps.layoutMap;
const headerNodes = layoutMap.getCellHeaderPathsWidthTreeNode(col, row);
return headerNodes;
}
_hasHierarchyTreeHeader() {
return (this.internalProps.layoutMap as PivotHeaderLayoutMap).rowHierarchyType === 'tree';
}
Expand Down
16 changes: 4 additions & 12 deletions packages/vtable/src/layout/pivot-header-layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1422,15 +1422,7 @@ export class PivotHeaderLayoutMap implements LayoutMapAPI {
// return { start: { col: 0, row: 0 }, end: { col: 0, row: 0 } };
// }

getCellHeaderPathsWidthTreeNode(
col: number,
row: number
): {
/** 列表头各级path表头信息 */
readonly colHeaderPaths?: any[];
/** 行表头各级path表头信息 */
readonly rowHeaderPaths?: any[];
} {
getCellHeaderPathsWidthTreeNode(col: number, row: number): IPivotTableCellHeaderPaths {
// if (this._CellHeaderPathMap.has(`$${col}$${row}`))
if (this._CellHeaderPathMap.has(`${col}-${row}`)) {
return this._CellHeaderPathMap.get(`${col}-${row}`);
Expand Down Expand Up @@ -1513,7 +1505,7 @@ export class PivotHeaderLayoutMap implements LayoutMapAPI {
const headerPaths: IPivotTableCellHeaderPaths = {
colHeaderPaths: [],
rowHeaderPaths: [],
cellLocation: this.getCellLocation(col, row)
cellLocation: headerPathsWidthNode.cellLocation
};
headerPathsWidthNode.colHeaderPaths?.forEach((colHeader: any) => {
const colHeaderPath: {
Expand Down Expand Up @@ -2020,8 +2012,8 @@ export class PivotHeaderLayoutMap implements LayoutMapAPI {
} else if (this.isRowHeader(source.col, source.row)) {
// 插入目标地址的列index
let targetIndex;
const sourceRowHeaderPaths = this.getCellHeaderPathsWidthTreeNode(source.col, source.row).rowHeaderPaths;
const targetRowHeaderPaths = this.getCellHeaderPathsWidthTreeNode(target.col, target.row).rowHeaderPaths;
const sourceRowHeaderPaths = this.getCellHeaderPathsWidthTreeNode(source.col, source.row).rowHeaderPaths as any;
const targetRowHeaderPaths = this.getCellHeaderPathsWidthTreeNode(target.col, target.row).rowHeaderPaths as any;
const sourceRowHeaderNode = sourceRowHeaderPaths[sourceRowHeaderPaths.length - 1];
const targetRowHeaderNode = targetRowHeaderPaths[sourceRowHeaderPaths.length - 1];
//整体移动的列数
Expand Down
6 changes: 4 additions & 2 deletions packages/vtable/src/state/cell-move/adjust-header.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ export function adjustMoveHeaderTarget(source: CellAddress, target: CellAddress,
// tree模式[透视表行表头]
const layoutMap = table.internalProps.layoutMap as PivotHeaderLayoutMap;
if (layoutMap.rowHierarchyType === 'tree') {
const sourceRowHeaderPaths = layoutMap.getCellHeaderPathsWidthTreeNode(source.col, source.row).rowHeaderPaths;
const targetRowHeaderPaths = layoutMap.getCellHeaderPathsWidthTreeNode(target.col, target.row).rowHeaderPaths;
const sourceRowHeaderPaths = layoutMap.getCellHeaderPathsWidthTreeNode(source.col, source.row)
.rowHeaderPaths as any;
const targetRowHeaderPaths = layoutMap.getCellHeaderPathsWidthTreeNode(target.col, target.row)
.rowHeaderPaths as any;
if (sourceRowHeaderPaths.length <= targetRowHeaderPaths.length) {
const targetPathNode = targetRowHeaderPaths[sourceRowHeaderPaths.length - 1]; //找到共同层级节点
// 根据这个目标节点找到结束的row index
Expand Down

0 comments on commit eb0e650

Please sign in to comment.