diff --git a/src/selection.js b/src/selection.js index 8885f9f..a79b101 100644 --- a/src/selection.js +++ b/src/selection.js @@ -31,31 +31,24 @@ export const createSelectionManager = (container, state) => { const body = container.querySelector('.dt-body'); if (!body) return; - // Fast path: Use children instead of querySelectorAll - const nodes = body.children; - for (let r = 0; r < nodes.length; r++) { - const rowNode = nodes[r]; - if (!rowNode.classList.contains('dt-body-row')) continue; - + const rowNodes = body.querySelectorAll('.dt-body-row'); + rowNodes.forEach(rowNode => { const absoluteRow = (rowNode._ref?.rIdx ?? -1) + state._listStartIndex; + const cells = rowNode.querySelectorAll('.dt-cell'); if (!hasSelection || absoluteRow < boundMinRow || absoluteRow > boundMaxRow) { - // Clear all cells in row without checking individually if possible - const cellNodes = rowNode.children; - for (let i = 0; i < cellNodes.length; i++) { - cellNodes[i].classList.remove('dt-cell-selected'); - } - continue; + cells.forEach(cell => cell.classList.remove('dt-cell-selected')); + return; } - const cellNodes = rowNode.children; - for (let i = 0; i < cellNodes.length; i++) { - const isSelected = isCellSelected(absoluteRow, i); - const cell = cellNodes[i]; - if (isSelected) cell.classList.add('dt-cell-selected'); - else cell.classList.remove('dt-cell-selected'); - } - } + cells.forEach((cell, cIdx) => { + if (isCellSelected(absoluteRow, cIdx)) { + cell.classList.add('dt-cell-selected'); + } else { + cell.classList.remove('dt-cell-selected'); + } + }); + }); }; const updateStatus = () => {