#90 handle native json field in datagrid

This commit is contained in:
Jan Prochazka 2021-04-24 12:24:58 +02:00
parent c30724c5da
commit 7524b30f50
5 changed files with 48 additions and 10 deletions

View File

@ -1,6 +1,19 @@
<script lang="ts"> <script lang="ts">
import _ from 'lodash';
export let selection; export let selection;
export let wrap; export let wrap;
</script> </script>
<textarea class="flex1" {wrap} readonly value={selection.map(cell => cell.value).join('\n')} /> <textarea
class="flex1"
{wrap}
readonly
value={selection
.map(cell => {
const { value } = cell;
if (_.isPlainObject(value) || _.isArray(value)) return JSON.stringify(value, undefined, 2);
return cell.value;
})
.join('\n')}
/>

View File

@ -100,7 +100,7 @@
{:else if value.type == 'Buffer' && _.isArray(value.data)} {:else if value.type == 'Buffer' && _.isArray(value.data)}
<span class="null">({value.data.length} bytes)</span> <span class="null">({value.data.length} bytes)</span>
{:else if _.isPlainObject(value)} {:else if _.isPlainObject(value)}
<span class="null">(JSON)</span> <span class="null" title={JSON.stringify(value, undefined, 2)}>(JSON)</span>
{:else if _.isArray(value)} {:else if _.isArray(value)}
<span class="null">[{value.length} items]</span> <span class="null">[{value.length} items]</span>
{:else} {:else}

View File

@ -161,6 +161,13 @@
if (allRowCount == null) return 'Loading row count...'; if (allRowCount == null) return 'Loading row count...';
return `Rows: ${allRowCount.toLocaleString()}`; return `Rows: ${allRowCount.toLocaleString()}`;
} }
function getCopiedValue(value) {
if (value === null) return '(NULL)';
if (value === undefined) return '(NoField)';
if (_.isPlainObject(value) || _.isArray(value)) return JSON.stringify(value);
return value;
}
</script> </script>
<script lang="ts"> <script lang="ts">
@ -329,7 +336,7 @@
if (!rowData) return ''; if (!rowData) return '';
const line = colIndexes const line = colIndexes
.map(col => realColumnUniqueNames[col]) .map(col => realColumnUniqueNames[col])
.map(col => (rowData[col] == null ? '(NULL)' : rowData[col])) .map(col => getCopiedValue(rowData[col]))
.join('\t'); .join('\t');
return line; return line;
}); });

View File

@ -1,7 +1,15 @@
<script lang="ts" context="module">
function getEditedValue(value) {
if (_.isPlainObject(value) || _.isArray(value)) return JSON.stringify(value);
return value;
}
</script>
<script lang="ts"> <script lang="ts">
import keycodes from '../utility/keycodes'; import keycodes from '../utility/keycodes';
import { onMount } from 'svelte'; import { onMount } from 'svelte';
import createRef from '../utility/createRef'; import createRef from '../utility/createRef';
import _ from 'lodash';
export let inplaceEditorState; export let inplaceEditorState;
export let dispatchInsplaceEditor; export let dispatchInsplaceEditor;
@ -54,7 +62,7 @@
} }
onMount(() => { onMount(() => {
domEditor.value = inplaceEditorState.text || cellValue; domEditor.value = inplaceEditorState.text || getEditedValue(cellValue);
domEditor.focus(); domEditor.focus();
if (inplaceEditorState.selectAll) { if (inplaceEditorState.selectAll) {
domEditor.select(); domEditor.select();

File diff suppressed because one or more lines are too long