Update bulk cell selection to support sticky column

This commit is contained in:
Andrew Kingston 2024-06-21 11:15:41 +01:00
parent 7349910572
commit a86f891c04
No known key found for this signature in database
2 changed files with 25 additions and 7 deletions

View File

@ -53,7 +53,19 @@ export const deriveStores = context => {
([$columns, $stickyColumn]) => { ([$columns, $stickyColumn]) => {
let allCols = $columns || [] let allCols = $columns || []
if ($stickyColumn) { if ($stickyColumn) {
allCols = [...allCols, $stickyColumn] allCols = [$stickyColumn, ...allCols]
}
return allCols
}
)
// Quick access to all visible columns
const allVisibleColumns = derived(
[visibleColumns, stickyColumn],
([$visibleColumns, $stickyColumn]) => {
let allCols = $visibleColumns || []
if ($stickyColumn) {
allCols = [$stickyColumn, ...allCols]
} }
return allCols return allCols
} }
@ -68,9 +80,9 @@ export const deriveStores = context => {
}) })
// Derive a lookup map for column indices by name // Derive a lookup map for column indices by name
const columnLookupMap = derived(visibleColumns, $visibleColumns => { const columnLookupMap = derived(allVisibleColumns, $allVisibleColumns => {
let map = {} let map = {}
$visibleColumns.forEach((column, idx) => { $allVisibleColumns.forEach((column, idx) => {
map[column.name] = idx map[column.name] = idx
}) })
return map return map
@ -78,6 +90,7 @@ export const deriveStores = context => {
return { return {
allColumns, allColumns,
allVisibleColumns,
hasNonAutoColumn, hasNonAutoColumn,
columnLookupMap, columnLookupMap,
} }

View File

@ -14,8 +14,13 @@ export const createStores = () => {
} }
export const deriveStores = context => { export const deriveStores = context => {
const { cellSelection, rowLookupMap, columnLookupMap, rows, visibleColumns } = const {
context cellSelection,
rowLookupMap,
columnLookupMap,
rows,
allVisibleColumns,
} = context
const isSelectingCells = derived(cellSelection, $cellSelection => { const isSelectingCells = derived(cellSelection, $cellSelection => {
return $cellSelection.active return $cellSelection.active
@ -29,7 +34,7 @@ export const deriveStores = context => {
return {} return {}
} }
const $rows = get(rows) const $rows = get(rows)
const $visibleColumns = get(visibleColumns) const $allVisibleColumns = get(allVisibleColumns)
// Get source and target row and column indices // Get source and target row and column indices
const sourceInfo = parseCellID(sourceCellId) const sourceInfo = parseCellID(sourceCellId)
@ -53,7 +58,7 @@ export const deriveStores = context => {
for (let rowIdx = lowerRowIndex; rowIdx <= upperRowIndex; rowIdx++) { for (let rowIdx = lowerRowIndex; rowIdx <= upperRowIndex; rowIdx++) {
for (let colIdx = lowerColIndex; colIdx <= upperColIndex; colIdx++) { for (let colIdx = lowerColIndex; colIdx <= upperColIndex; colIdx++) {
rowId = $rows[rowIdx]._id rowId = $rows[rowIdx]._id
colName = $visibleColumns[colIdx].name colName = $allVisibleColumns[colIdx].name
cellId = getCellID(rowId, colName) cellId = getCellID(rowId, colName)
map[cellId] = true map[cellId] = true
} }