diff --git a/packages/web/src/celldata/TableCellView.svelte b/packages/web/src/celldata/TableCellView.svelte index a6af06974..d441ca0bc 100644 --- a/packages/web/src/celldata/TableCellView.svelte +++ b/packages/web/src/celldata/TableCellView.svelte @@ -12,7 +12,7 @@ import SearchBoxWrapper from '../elements/SearchBoxWrapper.svelte'; import SearchInput from '../elements/SearchInput.svelte'; import CloseSearchButton from '../buttons/CloseSearchButton.svelte'; - import { _t } from '../translations' + import { _t } from '../translations'; export let selection; @@ -22,7 +22,7 @@ $: editorTypes = firstSelection?.editorTypes; $: displayColumns = firstSelection?.displayColumns || []; $: realColumnUniqueNames = firstSelection?.realColumnUniqueNames || []; - $: setCellValue = selection?.setCellValue; + $: grider = firstSelection?.grider; $: uniqueRows = _.uniqBy(selection || [], 'row'); $: isMultipleRows = uniqueRows.length > 1; @@ -77,7 +77,13 @@ const isChangedRef = createRef(false); function isJsonValue(value) { - if (_.isPlainObject(value) && !(value?.type == 'Buffer' && _.isArray(value.data)) && !value.$oid && !value.$bigint && !value.$decimal) { + if ( + _.isPlainObject(value) && + !(value?.type == 'Buffer' && _.isArray(value.data)) && + !value.$oid && + !value.$bigint && + !value.$decimal + ) { return true; } if (_.isArray(value)) return true; @@ -94,7 +100,7 @@ } function handleDoubleClick(field) { - if (!editable || !setCellValue) return; + if (!editable || !grider) return; if (isJsonValue(field.value) && !field.hasMultipleValues) { openEditModal(field); return; @@ -103,7 +109,7 @@ } function startEditing(field) { - if (!editable || !setCellValue) return; + if (!editable || !grider) return; editingColumn = field.uniqueName; editValue = field.hasMultipleValues ? '' : stringifyCellValue(field.value, 'inlineEditorIntent', editorTypes).value; isChangedRef.set(false); @@ -142,7 +148,7 @@ const currentIndex = filteredFields.findIndex(f => f.uniqueName === field.uniqueName); const nextIndex = reverse ? currentIndex - 1 : currentIndex + 1; if (nextIndex < 0 || nextIndex >= filteredFields.length) return; - + tick().then(() => { const nextField = filteredFields[nextIndex]; if (isJsonValue(nextField.value)) { @@ -168,15 +174,28 @@ editingColumn = null; } + function setCellValue(fieldName, value) { + if (!grider) return; + + if (selection.length > 0) { + const uniqueRowIndices = _.uniq(selection.map(x => x.row)); + grider.beginUpdate(); + for (const row of uniqueRowIndices) { + grider.setCellValue(row, fieldName, value); + } + grider.endUpdate(); + } + } + function saveValue(field) { - if (!setCellValue) return; + if (!grider) return; const parsedValue = parseCellValue(editValue, editorTypes); setCellValue(field.uniqueName, parsedValue); isChangedRef.set(false); } function openEditModal(field) { - if (!setCellValue) return; + if (!grider) return; showModal(EditCellDataModal, { value: field.value, dataEditorTypesBehaviour: editorTypes, @@ -201,63 +220,61 @@ {#if rowData}