import { ColumnDef, Row } from '@tanstack/react-table'; import { Checkbox } from '@@/form-components/Checkbox'; export function createSelectColumn(): ColumnDef { let lastSelectedId = ''; return { id: 'select', header: ({ table }) => ( !row.getCanSelect())} onClick={(e) => { e.stopPropagation(); }} /> ), cell: ({ row, table }) => ( { e.stopPropagation(); if (e.shiftKey) { const { rows, rowsById } = table.getRowModel(); const rowsToToggle = getRowRange(rows, row.id, lastSelectedId); const isLastSelected = rowsById[lastSelectedId].getIsSelected(); rowsToToggle.forEach((row) => row.toggleSelected(isLastSelected)); } lastSelectedId = row.id; }} /> ), enableHiding: false, meta: { width: 50, }, }; } function getRowRange(rows: Array>, idA: string, idB: string) { const range: Array> = []; let foundStart = false; let foundEnd = false; for (let index = 0; index < rows.length; index += 1) { const row = rows[index]; if (row.id === idA || row.id === idB) { if (foundStart) { foundEnd = true; } if (!foundStart) { foundStart = true; } } if (foundStart) { range.push(row); } if (foundEnd) { break; } } return range; }