1
0
Fork 0
mirror of synced 2024-07-06 15:00:49 +12:00

Add option to duplicate columns

This commit is contained in:
Andrew Kingston 2023-09-06 16:56:27 +01:00
parent cc38c1d294
commit 0bda4a1952
3 changed files with 42 additions and 1 deletions

View file

@ -56,7 +56,10 @@
isActive: () => api?.isActive?.() ?? false,
onKeyDown: (...params) => api?.onKeyDown(...params),
isReadonly: () => readonly,
getType: () => column.schema.type,
getType: () => {
console.log("getType", column)
return column.schema.type
},
getValue: () => row[column.name],
setValue: (value, options = { save: true }) => {
validation.actions.setError(cellId, null)

View file

@ -20,6 +20,8 @@
config,
ui,
columns,
definition,
datasource,
} = getContext("grid")
const bannedDisplayColumnTypes = [
@ -118,6 +120,33 @@
open = false
}
const duplicateColumn = async () => {
open = false
// Generate new name
let newName = `${column.name} copy`
let attempts = 2
while ($definition.schema[newName]) {
newName = `${column.name} copy ${attempts++}`
}
// Save schema with new column
const existingColumnDefinition = $definition.schema[column.name]
await datasource.actions.saveDefinition({
...$definition,
schema: {
...$definition.schema,
[newName]: {
...existingColumnDefinition,
name: newName,
schema: {
...existingColumnDefinition.schema,
},
},
},
})
}
onMount(() => subscribe("close-edit-column", cancelEdit))
</script>
@ -192,6 +221,13 @@
>
Edit column
</MenuItem>
<MenuItem
icon="Duplicate"
on:click={duplicateColumn}
disabled={!$config.canEditColumns}
>
Duplicate column
</MenuItem>
<MenuItem
icon="Label"
on:click={makeDisplayColumn}

View file

@ -212,8 +212,10 @@
// Focuses the cell and starts entering a new value
const startEnteringValue = (key, keyCode) => {
console.log("start", $focusedCellAPI, $focusedCellAPI.isReadonly())
if ($focusedCellAPI && !$focusedCellAPI.isReadonly()) {
const type = $focusedCellAPI.getType()
console.log(type)
if (type === "number" && keyCodeIsNumber(keyCode)) {
// Update the value locally but don't save it yet
$focusedCellAPI.setValue(parseInt(key), { save: false })