From 6df8d8976d7bfa6157beabf2894e9e555ce629a3 Mon Sep 17 00:00:00 2001 From: zzh <1368735060@qq.com> Date: Mon, 19 Oct 2026 18:59:12 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20HandsontablePro=20=E9=80=89=E4=B8=AD?= =?UTF-8?q?=E8=A1=8C=E9=AB=98=E4=BA=AE=E6=8C=89=E8=A7=86=E8=A7=89=E8=A1=8C?= =?UTF-8?q?=E5=8F=B7=E5=8C=B9=E9=85=8D=EF=BC=8C=E4=BF=AE=E5=A4=8D=E6=BB=9A?= =?UTF-8?q?=E5=8A=A8=E5=90=8E=E7=82=B9=E5=87=BB=E9=AB=98=E4=BA=AE=E9=94=99?= =?UTF-8?q?=E8=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Cursor --- src/components/HandsontablePro/index.vue | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/components/HandsontablePro/index.vue b/src/components/HandsontablePro/index.vue index 33cb394..bda9ae2 100644 --- a/src/components/HandsontablePro/index.vue +++ b/src/components/HandsontablePro/index.vue @@ -2046,6 +2046,7 @@ }; removeFilterIconFromColumns(); syncHybridHeaders(); + applySelectedRowStyles(); remasureActionColumnFromDom(); // remasure/updateSettings 后 HOT 会按原生滚动条再次缩短 clone,需再对齐一次 scheduleCloneOverlaySync(); @@ -2443,15 +2444,14 @@ const tbody = hotContainer.value.querySelector('.ht_master tbody'); if (!tbody) return; + // HOT 虚拟滚动只渲染可视区行且复用 tr,DOM 下标 ≠ 视觉行号,须按单元格坐标取行 const rows = tbody.querySelectorAll('tr'); - rows.forEach((row, index) => { - // 移除之前的所有选中状态 - row.classList.remove('selected-row'); - - // 为当前选中的行添加类 - if (selectedRowIndicesSet.value.has(index)) { - row.classList.add('selected-row'); - } + rows.forEach((row) => { + const cell = row.querySelector('td, th') as HTMLTableCellElement | null; + const visualRow = cell ? hotInstance!.getCoords(cell)?.row : undefined; + const selected = + typeof visualRow === 'number' && visualRow >= 0 && selectedRowIndicesSet.value.has(visualRow); + row.classList.toggle('selected-row', selected); }); };