Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"changes": [
{
"comment": "feat: add updateOption api\n\n",
"type": "minor",
"packageName": "@visactor/vtable"
}
],
"packageName": "@visactor/vtable",
"email": "892739385@qq.com"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"changes": [
{
"comment": "feat: add updateOption api for vtable-sheet\n\n",
"type": "none",
"packageName": "@visactor/vtable"
}
],
"packageName": "@visactor/vtable",
"email": "892739385@qq.com"
}
8 changes: 8 additions & 0 deletions docs/assets/api/en/SheetAPI.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@

VTableSheet instance supports the following methods:

### updateOption(Function)

Update table configuration options, automatically redraws after calling.
```
updateOption: (options: Partial<IVTableSheetOptions>) => void
```
This interface supports full update and incremental update. Full update will relayout and render the entire table, incremental update will only update the configuration items, not relayout and render the entire table.

### activateSheet(Function)

Activate the specified sheet
Expand Down
9 changes: 9 additions & 0 deletions docs/assets/api/zh/SheetAPI.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@

VTableSheet组件支持的方法如下:

### updateOption(Function)

更新表格配置项,调用后会自动重绘。
```
updateOption: (options: Partial<IVTableSheetOptions>) => void
```

该接口支持全量更新和增量更新,全量更新会重新布局和渲染整个表格,增量更新只会更新配置项,不会重新布整个表格。

### activateSheet(Function)

激活指定sheet
Expand Down
19 changes: 11 additions & 8 deletions packages/vtable-sheet/__tests__/complete-tab-switching-fix.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,8 @@ describe('Complete Tab Switching Fix', () => {
// Switch back to Sheet1 and verify formula behavior
formulaManager.setActiveSheet('Sheet1');
expect(formulaManager.getCellValue({ sheet: 'Sheet1', row: 2, col: 2 }).value).toBe(100); // Uses Sheet1's B2
// Note: Currently relative references use the active sheet context, so Sheet2's formula uses Sheet1's B2
// This may be a bug - ideally Sheet2's formula should reference Sheet2's B2 regardless of active sheet
expect(formulaManager.getCellValue({ sheet: 'Sheet2', row: 2, col: 2 }).value).toBe(100); // Currently uses active sheet (Sheet1) context
// Relative references应以公式所属 sheet 为上下文
expect(formulaManager.getCellValue({ sheet: 'Sheet2', row: 2, col: 2 }).value).toBe(1000); // Uses Sheet2's B2
});

test('should handle tab switching with newly created sheets correctly', () => {
Expand Down Expand Up @@ -178,7 +177,9 @@ describe('Complete Tab Switching Fix', () => {
]);
const summarySheetData = normalizeTestData([
['A', 'B'], // row 0
['', ''] // row 1
['', ''], // row 1
['', ''], // row 2
['', ''] // row 3
]);

formulaManager.addSheet('DataSheet1', dataSheet1Data);
Expand All @@ -201,15 +202,17 @@ describe('Complete Tab Switching Fix', () => {
formulaManager.setCellContent({ sheet: 'SummarySheet', row: 1, col: 1 }, '=SUM(DataSheet1!A2:B3)');
expect(formulaManager.getCellValue({ sheet: 'SummarySheet', row: 1, col: 1 }).value).toBe(100); // 10+20+30+40

// Switch to DataSheet2 and create formula that uses active sheet context (implicit reference)
// Switch to DataSheet2 and create formula (implicit reference uses SummarySheet context)
formulaManager.setActiveSheet('DataSheet2');
formulaManager.setCellContent({ sheet: 'SummarySheet', row: 2, col: 1 }, '=SUM(A2:B3)'); // Should use DataSheet2
expect(formulaManager.getCellValue({ sheet: 'SummarySheet', row: 2, col: 1 }).value).toBe(1000); // 100+200+300+400
// 放在 B4,避免 SUM(A2:B3) 自引用
formulaManager.setCellContent({ sheet: 'SummarySheet', row: 3, col: 1 }, '=SUM(A2:B3)');
// 目前隐式引用会落到默认 sheet(DataSheet1)
expect(formulaManager.getCellValue({ sheet: 'SummarySheet', row: 3, col: 1 }).value).toBe(100);

// Switch back to DataSheet1 and verify behavior
formulaManager.setActiveSheet('DataSheet1');
expect(formulaManager.getCellValue({ sheet: 'SummarySheet', row: 1, col: 1 }).value).toBe(100); // Explicit reference should be unchanged
expect(formulaManager.getCellValue({ sheet: 'SummarySheet', row: 2, col: 1 }).value).toBe(1000); // Should still be 1000 (implicit reference uses DataSheet2 which was active when formula was created)
expect(formulaManager.getCellValue({ sheet: 'SummarySheet', row: 3, col: 1 }).value).toBe(100);
});

test('should handle edge case of switching to non-existent sheet then creating it', () => {
Expand Down
Loading
Loading