From d3476356885d4fda2af1c3ddc927eccd1f1b9f76 Mon Sep 17 00:00:00 2001 From: Miosas Date: Sun, 4 Jan 2026 16:04:25 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=A1=A8=E6=A0=BC?= =?UTF-8?q?=E9=87=8D=E7=BB=98=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- entry/src/main/ets/pages/Index.ets | 1 + .../src/main/ets/util/VTableController.ets | 26 ++++++++++++++----- .../src/main/resources/rawfile/vtable_util.js | 5 ++++ 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/entry/src/main/ets/pages/Index.ets b/entry/src/main/ets/pages/Index.ets index 3b00f1d..690c88f 100644 --- a/entry/src/main/ets/pages/Index.ets +++ b/entry/src/main/ets/pages/Index.ets @@ -186,6 +186,7 @@ struct Index { break case DialogType.UNFREEZE_ROW: this.vTableController.frozenRow(1) + this.vTableController.renderWithRecreateCells() break case DialogType.UNFREEZE_COLUMN: this.vTableController.frozenToCol(0) diff --git a/library/src/main/ets/util/VTableController.ets b/library/src/main/ets/util/VTableController.ets index 7405725..8035501 100644 --- a/library/src/main/ets/util/VTableController.ets +++ b/library/src/main/ets/util/VTableController.ets @@ -144,15 +144,16 @@ export class VTableController { } // 自定义渲染 - customRender(startCol: number, startRow: number, endCol: number, endRow: number,id:string = 'default',style?:Record){ + customRender(startCol: number, startRow: number, endCol: number, endRow: number, id: string = 'default', + style?: Record) { if (!this.checkInitialized()) { return; } - const deStyle:Record = { - "borderColor":"red", - "borderLineWidth":4, - "fontSize":20, - "bgColor":"yellow", + const deStyle: Record = { + "borderColor": "red", + "borderLineWidth": 4, + "fontSize": 20, + "bgColor": "yellow", } const deStyleStr = JSON.stringify(deStyle) const styleStr = JSON.stringify(style) @@ -161,6 +162,7 @@ export class VTableController { console.error("Error customRender:", error); }) } + // 取消自定义渲染 cancelCustomRender(startCol: number, startRow: number, endCol: number, endRow: number) { if (!this.checkInitialized()) { @@ -250,7 +252,7 @@ export class VTableController { } // 更新表格参数 - updateOption(option: Record>){ + updateOption(option: Record>) { if (!this.checkInitialized()) { return; } @@ -270,6 +272,16 @@ export class VTableController { }) } + renderWithRecreateCells() { + if (!this.checkInitialized()) { + return; + } + this.controller!.runJavaScript(`renderWithRecreateCells()`) + .catch((error: Error) => { + console.error("Error renderWithRecreateCells:", error); + }) + } + release() { if (!this.checkInitialized()) { return; diff --git a/library/src/main/resources/rawfile/vtable_util.js b/library/src/main/resources/rawfile/vtable_util.js index 73e1a09..73791a1 100644 --- a/library/src/main/resources/rawfile/vtable_util.js +++ b/library/src/main/resources/rawfile/vtable_util.js @@ -389,4 +389,9 @@ function clearSelected() { function updateOption(options) { window.tableInstance.updateOption(options); +} + +function renderWithRecreateCells(){ + console.log("=====> renderWithRecreateCells") + window.tableInstance.renderWithRecreateCells(); } \ No newline at end of file -- Gitee From 982bccbecb8f52eabc3b3ec537cfa75f88056345 Mon Sep 17 00:00:00 2001 From: Miosas Date: Sun, 4 Jan 2026 16:47:51 +0800 Subject: [PATCH 2/2] aaa --- entry/src/main/ets/pages/Index.ets | 42 +++++++++++-------- .../src/main/ets/util/VTableController.ets | 3 +- .../src/main/resources/rawfile/vtable_util.js | 9 +--- 3 files changed, 29 insertions(+), 25 deletions(-) diff --git a/entry/src/main/ets/pages/Index.ets b/entry/src/main/ets/pages/Index.ets index 690c88f..08ab135 100644 --- a/entry/src/main/ets/pages/Index.ets +++ b/entry/src/main/ets/pages/Index.ets @@ -14,7 +14,7 @@ import { DialogType, OptionDialog } from './Dialog'; struct Index { dialogController?: CustomDialogController @State vTableController: VTableController = new VTableController(); - columns: Record>[] = [ + columns: Record>[] = [ { "field": "A", "title": "工号", @@ -91,7 +91,7 @@ struct Index { "columns": [], "records": [], "autoWrapText": true, - "defaultRowHeight": "auto", + "defaultRowHeight": 30, "editor": "input", "editCellTrigger": "doubleclick", "resize": { @@ -111,18 +111,18 @@ struct Index { "text": "bbb" }, ] - imageColumns: Record>[] = [ + imageColumns: Record>[] = [ { "field": "A", "title": "icon", "width": "auto", "editor": "input", - "icon":{ - "type":"image", + "icon": { + "type": "image", "src": "https://lf9-dp-fe-cms-tos.byteorg.com/obj/bit-cloud/VTable/custom-render/flower.jpg", - "width":12, - "height":12, - "positionType":"left" + "width": 12, + "height": 12, + "positionType": "left" } }, { @@ -517,19 +517,26 @@ struct Index { .onSelect((event) => { this.floatingWindowType = event }) - Button('取消选中') - .borderRadius(0) - .backgroundColor('#70949292') - .fontColor(Color.Black) - .onClick(() => { - console.log(`==========>this.isShow:`, JSON.stringify(this.isShow)) - this.vTableController.clearSelected() - }) + // Button('取消选中') + // .borderRadius(0) + // .backgroundColor('#70949292') + // .fontColor(Color.Black) + // .onClick(() => { + // console.log(`==========>this.isShow:`, JSON.stringify(this.isShow)) + // this.vTableController.clearSelected() + // }) Button('合并单元格') .borderRadius(0) .backgroundColor('#70949292') .fontColor(Color.Black) .onClick(() => { + this.vTableController.unmergeCells( + Math.min(this.mergeCellParams[0], this.mergeCellParams[2]), + Math.min(this.mergeCellParams[1], this.mergeCellParams[3]), + Math.max(this.mergeCellParams[0], this.mergeCellParams[2]), + Math.max(this.mergeCellParams[1], this.mergeCellParams[3]) + ); + this.vTableController.mergeCell( Math.min(this.mergeCellParams[0], this.mergeCellParams[2]), Math.min(this.mergeCellParams[1], this.mergeCellParams[3]), @@ -566,7 +573,8 @@ struct Index { .backgroundColor('#70949292') .fontColor(Color.Black) .onClick(() => { - this.vTableController.cancelCustomRender(this.mergeCellParams[0], this.mergeCellParams[1],this.mergeCellParams[2], this.mergeCellParams[3]) + this.vTableController.cancelCustomRender(this.mergeCellParams[0], this.mergeCellParams[1], + this.mergeCellParams[2], this.mergeCellParams[3]) }) } diff --git a/library/src/main/ets/util/VTableController.ets b/library/src/main/ets/util/VTableController.ets index 8035501..15590c1 100644 --- a/library/src/main/ets/util/VTableController.ets +++ b/library/src/main/ets/util/VTableController.ets @@ -157,10 +157,11 @@ export class VTableController { } const deStyleStr = JSON.stringify(deStyle) const styleStr = JSON.stringify(style) - this.controller!.runJavaScript(`customRender(${startCol},${startRow},${endCol},${endRow},${id},${deStyleStr})`) + this.controller!.runJavaScript(`customRender(${startCol},${startRow},${endCol},${endRow},"${id}",${deStyleStr})`) .catch((error: Error) => { console.error("Error customRender:", error); }) + this.renderWithRecreateCells() } // 取消自定义渲染 diff --git a/library/src/main/resources/rawfile/vtable_util.js b/library/src/main/resources/rawfile/vtable_util.js index 73791a1..0e7ac10 100644 --- a/library/src/main/resources/rawfile/vtable_util.js +++ b/library/src/main/resources/rawfile/vtable_util.js @@ -238,12 +238,8 @@ function customRender(startCol, startRow, endCol, endRow, id, style) { } // 自定义渲染复原 function customRenderRestore(startCol, startRow, endCol, endRow) { - const style = { - borderColor:'', - borderLineWidth:0, - bgColor:'', - fontSize:null, - } + const style = window.tableInstance.theme.style + window.tableInstance.registerCustomCellStyle('none',style) const pos = { range:{ @@ -392,6 +388,5 @@ function updateOption(options) { } function renderWithRecreateCells(){ - console.log("=====> renderWithRecreateCells") window.tableInstance.renderWithRecreateCells(); } \ No newline at end of file -- Gitee