Skip to content

Commit

Permalink
Merge pull request #1014 from VisActor/1011-bug-bottomFrozenRow-click…
Browse files Browse the repository at this point in the history
…-scroll

1011 bug bottom frozen row click scroll
  • Loading branch information
fangsmile authored Jan 26, 2024
2 parents b2eb397 + 1b5062b commit 175fbb2
Show file tree
Hide file tree
Showing 10 changed files with 110 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"changes": [
{
"comment": "fix: when click bottomFrozenRow table scroll sometimes #1011\n\n",
"type": "none",
"packageName": "@visactor/vtable"
}
],
"packageName": "@visactor/vtable",
"email": "[email protected]"
}
24 changes: 24 additions & 0 deletions docs/assets/api/en/methods.md
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,30 @@ Get the text of the cell with omitted text.
getCellOverflowText(col: number, row: number) => string | null
```

## getCellRect(Function)
Get the specific position of the cell in the entire table.
```
/**
* Get the range of cells. The return value is Rect type. Regardless of whether it is a merged cell, the coordinates start from 0
* @param {number} col column index
* @param {number} row row index
* @returns {Rect}
*/
getCellRect(col: number, row: number): Rect
```

## getCellRelativeRect(Function)
Get the specific position of the cell in the entire table. Relative position is based on the upper left corner of the table (scroll condition minus scroll value)
```
/**
* The obtained position is relative to the upper left corner of the table display interface. In case of scrolling, if the cell has rolled out of the top of the table, the y of this cell will be a negative value.
* @param {number} col index of column, of the cell
* @param {number} row index of row, of the cell
* @returns {Rect} the rect of the cell.
*/
getCellRelativeRect(col: number, row: number): Rect
```

## getCellHeaderPaths(Function)

Get the path to the row list header
Expand Down
24 changes: 24 additions & 0 deletions docs/assets/api/zh/methods.md
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,30 @@ setRecords(records: Array<any>, sort?: SortState | SortState[]) //** 基本表
getCellOverflowText(col: number, row: number) => string | null
```

## getCellRect(Function)
获取单元格在整张表格中的具体位置。
```
/**
* 获取单元格的范围 返回值为Rect类型。不考虑是否为合并单元格的情况,坐标从0开始
* @param {number} col column index
* @param {number} row row index
* @returns {Rect}
*/
getCellRect(col: number, row: number): Rect
```

## getCellRelativeRect(Function)
获取单元格在整张表格中的具体位置。相对位置是基于表格左上角(滚动情况减去滚动值)
```
/**
* 获取的位置是相对表格显示界面的左上角 情况滚动情况 如单元格已经滚出表格上方 则这个单元格的y将为负值
* @param {number} col index of column, of the cell
* @param {number} row index of row, of the cell
* @returns {Rect} the rect of the cell.
*/
getCellRelativeRect(col: number, row: number): Rect
```

## getCellHeaderPaths(Function)

获取行列表头的路径
Expand Down
2 changes: 1 addition & 1 deletion docs/assets/demo/en/cell-type/chart.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
category: examples
group: Cell Type In PivotTable
group: Cell Type
title: Chart Type Use in PivotTable
cover: https://lf9-dp-fe-cms-tos.byteorg.com/obj/bit-cloud/VTable/preview/chart.png
link: '../guide/cell_type/chart'
Expand Down
2 changes: 1 addition & 1 deletion docs/assets/demo/en/cell-type/list-table-chart.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
category: examples
group: Cell Type In ListTable
group: Cell Type
title: List table integrated chart
cover: https://lf9-dp-fe-cms-tos.byteorg.com/obj/bit-cloud/VTable/preview/list-chart.png
link: '../guide/cell_type/chart'
Expand Down
2 changes: 1 addition & 1 deletion docs/assets/demo/en/edit/add-delete-records.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
category: examples
group: edit
title: add or delete records
cover: https://lf9-dp-fe-cms-tos.byteorg.com/obj/bit-cloud/VTable/preview/performance.gif
cover: https://lf9-dp-fe-cms-tos.byteorg.com/obj/bit-cloud/VTable/preview/add-delete-records.png
---

# Add and delete data dynamically
Expand Down
2 changes: 1 addition & 1 deletion docs/assets/demo/zh/cell-type/chart.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
category: examples
group: Cell Type In PivotTable
group: Cell Type
title: 透视表集成图表
cover: https://lf9-dp-fe-cms-tos.byteorg.com/obj/bit-cloud/VTable/preview/chart.png
link: '../guide/cell_type/chart'
Expand Down
2 changes: 1 addition & 1 deletion docs/assets/demo/zh/cell-type/list-table-chart.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
category: examples
group: Cell Type In ListTable
group: Cell Type
title: 基本表格集成图表
cover: https://lf9-dp-fe-cms-tos.byteorg.com/obj/bit-cloud/VTable/preview/list-chart.png
link: '../guide/cell_type/chart'
Expand Down
2 changes: 1 addition & 1 deletion docs/assets/demo/zh/edit/add-delete-records.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
category: examples
group: edit
title: 动态添加删除数据
cover: https://lf9-dp-fe-cms-tos.byteorg.com/obj/bit-cloud/VTable/preview/performance.gif
cover: https://lf9-dp-fe-cms-tos.byteorg.com/obj/bit-cloud/VTable/preview/add-delete-records.png
---

# 动态添加删除数据
Expand Down
52 changes: 45 additions & 7 deletions packages/vtable/src/core/BaseTable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1273,7 +1273,7 @@ export abstract class BaseTable extends EventTarget implements BaseTableAPI {
const height = this.getRowHeight(row);
if (isFrozenCell && isFrozenCell.row) {
if (this.isBottomFrozenRow(col, row)) {
absoluteLeft = this.tableNoFrameHeight - (this.getRowsHeight(row, this.rowCount - 1) ?? 0);
absoluteTop = this.tableNoFrameHeight - (this.getRowsHeight(row, this.rowCount - 1) ?? 0);
} else {
absoluteTop = this.getRowsHeight(0, row - 1);
absoluteTop += this.scrollTop;
Expand Down Expand Up @@ -1304,7 +1304,19 @@ export abstract class BaseTable extends EventTarget implements BaseTableAPI {
* @returns {Rect} the rect of the cell.
*/
getCellRelativeRect(col: number, row: number): Rect {
return this._toRelativeRect(this.getCellRect(col, row));
const isFrozenCell = this.isFrozenCell(col, row);
let relativeX = true;
let relativeY = true;
if (isFrozenCell?.col && isFrozenCell?.row) {
relativeX = false;
relativeY = false;
} else if (isFrozenCell?.col) {
relativeX = false;
} else if (isFrozenCell?.row) {
relativeY = false;
}
const cellRect = this.getCellRect(col, row);
return this._toRelativeRect(cellRect, relativeX, relativeY);
}
/**
* 获取的位置是相对表格显示界面的左上角
Expand All @@ -1313,18 +1325,44 @@ export abstract class BaseTable extends EventTarget implements BaseTableAPI {
*/
getCellRangeRelativeRect(range: CellRange | CellAddress): Rect {
if ((<CellRange>range).start) {
const isFrozenCell = this.isFrozenCell((<CellRange>range).start.col, (<CellRange>range).start.row);
let relativeX = true;
let relativeY = true;
if (isFrozenCell?.col && isFrozenCell?.row) {
relativeX = false;
relativeY = false;
} else if (isFrozenCell?.col) {
relativeX = false;
} else if (isFrozenCell?.row) {
relativeY = false;
}
return this._toRelativeRect(
this.getCellsRect(
(<CellRange>range).start.col,
(<CellRange>range).start.row,
(<CellRange>range).end.col,
(<CellRange>range).end.row
)
),
relativeX,
relativeY
);
}
const cellRange = this.getCellRange((<CellAddress>range).col, (<CellAddress>range).row);
const isFrozenCell = this.isFrozenCell((<CellAddress>range).col, (<CellAddress>range).row);
let relativeX = true;
let relativeY = true;
if (isFrozenCell?.col && isFrozenCell?.row) {
relativeX = false;
relativeY = false;
} else if (isFrozenCell?.col) {
relativeX = false;
} else if (isFrozenCell?.row) {
relativeY = false;
}
return this._toRelativeRect(
this.getCellsRect(cellRange.start.col, cellRange.start.row, cellRange.end.col, cellRange.end.row)
this.getCellsRect(cellRange.start.col, cellRange.start.row, cellRange.end.col, cellRange.end.row),
relativeX,
relativeY
);
}
/**
Expand Down Expand Up @@ -1612,11 +1650,11 @@ export abstract class BaseTable extends EventTarget implements BaseTableAPI {
* @param absoluteRect
* @returns
*/
_toRelativeRect(absoluteRect: Rect): Rect {
_toRelativeRect(absoluteRect: Rect, relativeX: boolean = true, relativeY: boolean = true): Rect {
const rect = absoluteRect.copy();
const visibleRect = this.getVisibleRect();
rect.offsetLeft(this.tableX - visibleRect.left);
rect.offsetTop(this.tableY - visibleRect.top);
rect.offsetLeft(this.tableX - (relativeX ? visibleRect.left : 0));
rect.offsetTop(this.tableY - (relativeY ? visibleRect.top : 0));
return rect;
}

Expand Down

0 comments on commit 175fbb2

Please sign in to comment.