Add option to duplicate columns
This commit is contained in:
parent
cc38c1d294
commit
0bda4a1952
|
@ -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)
|
||||
|
|
|
@ -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}
|
||||
|
|
|
@ -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 })
|
||||
|
|
Loading…
Reference in New Issue