fix editable property of columns being ignored in data_editor (#2338)

This commit is contained in:
Thomas Brandého 2023-12-28 09:09:07 +01:00 committed by GitHub
parent c5c42665eb
commit 78429866bd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,67 +1,69 @@
import { GridCellKind } from "@glideapps/glide-data-grid" import { GridCellKind } from "@glideapps/glide-data-grid";
export function getDEColumn(columns, col) { export function getDEColumn(columns, col) {
let c = columns[col]; let c = columns[col];
c.pos = col; c.pos = col;
return c; return c;
} }
export function getDERow(data, row) { export function getDERow(data, row) {
return data[row]; return data[row];
} }
export function locateCell(row, column) { export function locateCell(row, column) {
if (Array.isArray(row)) { if (Array.isArray(row)) {
return row[column.pos]; return row[column.pos];
} else { } else {
return row[column.id]; return row[column.id];
} }
} }
export function formatCell(value, column) { export function formatCell(value, column) {
const editable = column.editable || true const editable = column.editable ?? true;
switch (column.type) { switch (column.type) {
case "int": case "int":
case "float": case "float":
return { return {
kind: GridCellKind.Number, kind: GridCellKind.Number,
data: value, data: value,
displayData: value + "", displayData: value + "",
readonly: !editable, readonly: !editable,
allowOverlay: editable, allowOverlay: editable,
} };
case "datetime": case "datetime":
// value = moment format? // value = moment format?
case "str": case "str":
return { return {
kind: GridCellKind.Text, kind: GridCellKind.Text,
data: value, data: value,
displayData: value, displayData: value,
readonly: !editable, readonly: !editable,
allowOverlay: editable, allowOverlay: editable,
} };
case "bool": case "bool":
return { return {
kind: GridCellKind.Boolean, kind: GridCellKind.Boolean,
data: value, data: value,
readonly: !editable, readonly: !editable,
} };
default: default:
console.log("Warning: column.type is undefined for column.title=" + column.title) console.log(
return { "Warning: column.type is undefined for column.title=" + column.title
kind: GridCellKind.Text, );
data: value, return {
displayData: column.type kind: GridCellKind.Text,
} data: value,
}; displayData: column.type,
}; };
}
}
export function formatDataEditorCells(col, row, columns, data) { export function formatDataEditorCells(col, row, columns, data) {
if (row < data.length && col < columns.length) { if (row < data.length && col < columns.length) {
const column = getDEColumn(columns, col); const column = getDEColumn(columns, col);
const rowData = getDERow(data, row); const rowData = getDERow(data, row);
const cellData = locateCell(rowData, column); const cellData = locateCell(rowData, column);
return formatCell(cellData, column); return formatCell(cellData, column);
} }
return { kind: GridCellKind.Loading }; return { kind: GridCellKind.Loading };
} }