feat(grid): add boolean cell checkbox editing

This commit is contained in:
Diego Fabricio authored and GitHub committed 2026-08-03 15:08:09 +08:00
1 parent a537565875
commit a49e795680
6 files changed
+384 -19

No files matched your search

@@ -2,6 +2,7 @@ import { ref, shallowRef, computed, nextTick, watch, getCurrentInstance, onActiv
import * as api from "@/lib/backend/api";
import type { CellValue } from "@/lib/dataGrid/cellValue";
import { coerceDataGridCellValue, dataGridCellEditorText } from "@/lib/dataGrid/dataGridCellCoercion";
import { nextBooleanCellValue } from "@/lib/dataGrid/dataGridBooleanColumn";
import { focusDataGridEditorWithoutScrolling, preserveDataGridScrollPosition } from "@/lib/dataGrid/dataGridEditorFocus";
import { normalizeDataGridSaveError } from "@/lib/dataGrid/dataGridSql";
import { rowStatusFilterAfterAddingRow, type RowStatusFilter } from "@/lib/dataGrid/gridRowStatus";
@@ -47,7 +48,7 @@ type CommitEditResult =
interface CommitEditOptions {
promoteDraft?: boolean;
explicitValue?: string | null;
explicitValue?: CellValue;
}
type GridScrollerRef =
@@ -792,6 +793,19 @@ export function useDataGridEditor(options: UseDataGridEditorOptions) {
}
}
async function cycleBooleanCellValue(rowId: number, col: number, nullable: boolean) {
if (!editable.value || !canEditColumn(col)) return;
const item = getRowItem(rowId);
if (!item || item.isDeleted) return;
if (!item.isNew && !item.isDraft && !canEditExistingRows.value) return;
if (isSavingNewRow(item)) return;
const newVal = nextBooleanCellValue(item.data[col], nullable);
isCancelling = false;
suppressNextBlurCommit = false;
editingCell.value = { rowId, col };
await commitEditAndMaybeAutoSave({ explicitValue: newVal });
}
async function commitEditFromBlur(options: CommitEditOptions = {}) {
if (suppressNextBlurCommit) {
suppressNextBlurCommit = false;
@@ -1718,6 +1732,7 @@ export function useDataGridEditor(options: UseDataGridEditorOptions) {
startEdit,
commitEdit,
commitEditAndMaybeAutoSave,
cycleBooleanCellValue,
commitEditFromBlur,
applyCellValue,
restoreCellValue,