feat: add argument recalculateColWidths for api toggleHierarchyState #2817

This commit is contained in:
fangsmile 2024-11-12 18:15:18 +08:00
parent aaa03b6351
commit 4baffd9bac
3 changed files with 30 additions and 14 deletions

View File

@ -839,11 +839,11 @@ export class ListTable extends BaseTable implements ListTableAPI {
* @param col
* @param row
*/
toggleHierarchyState(col: number, row: number) {
toggleHierarchyState(col: number, row: number, recalculateColWidths: boolean = true) {
this.stateManager.updateHoverIcon(col, row, undefined, undefined);
const hierarchyState = this.getHierarchyState(col, row);
if (hierarchyState === HierarchyState.expand) {
this._refreshHierarchyState(col, row);
this._refreshHierarchyState(col, row, recalculateColWidths);
this.fireListeners(TABLE_EVENT_TYPE.TREE_HIERARCHY_STATE_CHANGE, {
col: col,
row: row,
@ -853,7 +853,7 @@ export class ListTable extends BaseTable implements ListTableAPI {
const record = this.getCellOriginRecord(col, row);
if (Array.isArray(record.children)) {
//children 是数组 表示已经有子树节点信息
this._refreshHierarchyState(col, row);
this._refreshHierarchyState(col, row, recalculateColWidths);
}
this.fireListeners(TABLE_EVENT_TYPE.TREE_HIERARCHY_STATE_CHANGE, {
col: col,
@ -864,7 +864,7 @@ export class ListTable extends BaseTable implements ListTableAPI {
}
}
/** 刷新当前节点收起展开状态,如手动更改过 */
_refreshHierarchyState(col: number, row: number) {
_refreshHierarchyState(col: number, row: number, recalculateColWidths: boolean = true) {
let notFillWidth = false;
let notFillHeight = false;
const checkHasChart = this.internalProps.layoutMap.checkHasChart();
@ -920,7 +920,12 @@ export class ListTable extends BaseTable implements ListTableAPI {
// reset proxy row config
this.scenegraph.proxy.refreshRowCount();
}
this.scenegraph.updateRow(diffPositions.removeCellPositions, diffPositions.addCellPositions, updateCells);
this.scenegraph.updateRow(
diffPositions.removeCellPositions,
diffPositions.addCellPositions,
updateCells,
recalculateColWidths
);
if (checkHasChart) {
// 检查更新节点状态后总宽高未撑满autoFill是否在起作用
if (this.autoFillWidth && !notFillWidth) {

View File

@ -1340,10 +1340,10 @@ export class PivotTable extends BaseTable implements PivotTableAPI {
* @param col
* @param row
*/
toggleHierarchyState(col: number, row: number) {
toggleHierarchyState(col: number, row: number, recalculateColWidths: boolean = true) {
const hierarchyState = this.getHierarchyState(col, row);
if (hierarchyState === HierarchyState.expand) {
this._refreshHierarchyState(col, row);
this._refreshHierarchyState(col, row, recalculateColWidths);
this.fireListeners(PIVOT_TABLE_EVENT_TYPE.TREE_HIERARCHY_STATE_CHANGE, {
col: col,
row: row,
@ -1358,7 +1358,7 @@ export class PivotTable extends BaseTable implements PivotTableAPI {
);
if (Array.isArray(headerTreeNode.children)) {
//children 是数组 表示已经有子树节点信息
this._refreshHierarchyState(col, row);
this._refreshHierarchyState(col, row, recalculateColWidths);
}
this.fireListeners(PIVOT_TABLE_EVENT_TYPE.TREE_HIERARCHY_STATE_CHANGE, {
col: col,
@ -1370,7 +1370,7 @@ export class PivotTable extends BaseTable implements PivotTableAPI {
}
// beforeUpdateCell主要用于setTreeNodeChildren方法
_refreshHierarchyState(col: number, row: number, beforeUpdateCell?: Function) {
_refreshHierarchyState(col: number, row: number, recalculateColWidths: boolean = true, beforeUpdateCell?: Function) {
let notFillWidth = false;
let notFillHeight = false;
this.stateManager.updateHoverIcon(col, row, undefined, undefined);
@ -1393,7 +1393,12 @@ export class PivotTable extends BaseTable implements PivotTableAPI {
// this.invalidate();
this.clearCellStyleCache();
this.scenegraph.updateHierarchyIcon(col, row);
this.scenegraph.updateRow(result.removeCellPositions, result.addCellPositions, result.updateCellPositions);
this.scenegraph.updateRow(
result.removeCellPositions,
result.addCellPositions,
result.updateCellPositions,
recalculateColWidths
);
if (checkHasChart) {
// 检查更新节点状态后总宽高未撑满autoFill是否在起作用
if (this.autoFillWidth && !notFillWidth) {
@ -1952,7 +1957,7 @@ export class PivotTable extends BaseTable implements PivotTableAPI {
row
);
headerTreeNode.children = children;
this._refreshHierarchyState(col, row, () => {
this._refreshHierarchyState(col, row, true, () => {
this.flatDataToObjects.changeDataConfig({
rows: this.internalProps.layoutMap.fullRowDimensionKeys,
columns: this.internalProps.layoutMap.colDimensionKeys,
@ -1970,7 +1975,7 @@ export class PivotTable extends BaseTable implements PivotTableAPI {
row
);
headerTreeNode.children = children;
this._refreshHierarchyState(col, row, () => {
this._refreshHierarchyState(col, row, true, () => {
this.dataset._rowTreeHasChanged();
this.dataset.changeDataConfig({
rows: this.internalProps.layoutMap.fullRowDimensionKeys,

View File

@ -1921,7 +1921,12 @@ export class Scenegraph {
this.stage.enableDirtyBounds();
}
updateRow(removeCells: CellAddress[], addCells: CellAddress[], updateCells: CellAddress[] = []) {
updateRow(
removeCells: CellAddress[],
addCells: CellAddress[],
updateCells: CellAddress[] = [],
recalculateColWidths: boolean = true
) {
this.table.internalProps.layoutMap.clearCellRangeMap();
this.table.internalProps.useOneRowHeightFillAll = false;
const addRows = deduplication(addCells.map(cell => cell.row)).sort((a, b) => a - b);
@ -1938,7 +1943,8 @@ export class Scenegraph {
updateRow(removeCells, addCells, updateCells, this.table);
// update column width and row height
this.recalculateColWidths();
recalculateColWidths && this.recalculateColWidths();
// this.recalculateRowHeights();