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]) => {
let allCols = $columns || []
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
}
@ -68,9 +80,9 @@ export const deriveStores = context => {
})
// Derive a lookup map for column indices by name
const columnLookupMap = derived(visibleColumns, $visibleColumns => {
const columnLookupMap = derived(allVisibleColumns, $allVisibleColumns => {
let map = {}
$visibleColumns.forEach((column, idx) => {
$allVisibleColumns.forEach((column, idx) => {
map[column.name] = idx
})
return map
@ -78,6 +90,7 @@ export const deriveStores = context => {
return {
allColumns,
allVisibleColumns,
hasNonAutoColumn,
columnLookupMap,
}

View File

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