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); }); };