Add option to duplicate columns
This commit is contained in:
parent
cc38c1d294
commit
0bda4a1952
|
@ -56,7 +56,10 @@
|
||||||
isActive: () => api?.isActive?.() ?? false,
|
isActive: () => api?.isActive?.() ?? false,
|
||||||
onKeyDown: (...params) => api?.onKeyDown(...params),
|
onKeyDown: (...params) => api?.onKeyDown(...params),
|
||||||
isReadonly: () => readonly,
|
isReadonly: () => readonly,
|
||||||
getType: () => column.schema.type,
|
getType: () => {
|
||||||
|
console.log("getType", column)
|
||||||
|
return column.schema.type
|
||||||
|
},
|
||||||
getValue: () => row[column.name],
|
getValue: () => row[column.name],
|
||||||
setValue: (value, options = { save: true }) => {
|
setValue: (value, options = { save: true }) => {
|
||||||
validation.actions.setError(cellId, null)
|
validation.actions.setError(cellId, null)
|
||||||
|
|
|
@ -20,6 +20,8 @@
|
||||||
config,
|
config,
|
||||||
ui,
|
ui,
|
||||||
columns,
|
columns,
|
||||||
|
definition,
|
||||||
|
datasource,
|
||||||
} = getContext("grid")
|
} = getContext("grid")
|
||||||
|
|
||||||
const bannedDisplayColumnTypes = [
|
const bannedDisplayColumnTypes = [
|
||||||
|
@ -118,6 +120,33 @@
|
||||||
open = false
|
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))
|
onMount(() => subscribe("close-edit-column", cancelEdit))
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
@ -192,6 +221,13 @@
|
||||||
>
|
>
|
||||||
Edit column
|
Edit column
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
|
<MenuItem
|
||||||
|
icon="Duplicate"
|
||||||
|
on:click={duplicateColumn}
|
||||||
|
disabled={!$config.canEditColumns}
|
||||||
|
>
|
||||||
|
Duplicate column
|
||||||
|
</MenuItem>
|
||||||
<MenuItem
|
<MenuItem
|
||||||
icon="Label"
|
icon="Label"
|
||||||
on:click={makeDisplayColumn}
|
on:click={makeDisplayColumn}
|
||||||
|
|
|
@ -212,8 +212,10 @@
|
||||||
|
|
||||||
// Focuses the cell and starts entering a new value
|
// Focuses the cell and starts entering a new value
|
||||||
const startEnteringValue = (key, keyCode) => {
|
const startEnteringValue = (key, keyCode) => {
|
||||||
|
console.log("start", $focusedCellAPI, $focusedCellAPI.isReadonly())
|
||||||
if ($focusedCellAPI && !$focusedCellAPI.isReadonly()) {
|
if ($focusedCellAPI && !$focusedCellAPI.isReadonly()) {
|
||||||
const type = $focusedCellAPI.getType()
|
const type = $focusedCellAPI.getType()
|
||||||
|
console.log(type)
|
||||||
if (type === "number" && keyCodeIsNumber(keyCode)) {
|
if (type === "number" && keyCodeIsNumber(keyCode)) {
|
||||||
// Update the value locally but don't save it yet
|
// Update the value locally but don't save it yet
|
||||||
$focusedCellAPI.setValue(parseInt(key), { save: false })
|
$focusedCellAPI.setValue(parseInt(key), { save: false })
|
||||||
|
|
Loading…
Reference in New Issue