Browse Source

feat(gui-v2): row insert

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/2947/head
Pranav C 2 years ago
parent
commit
2bf39dbd88
  1. 23
      packages/nc-gui-v2/components/smartsheet/Grid.vue
  2. 7
      packages/nc-gui-v2/composables/useViewData.ts

23
packages/nc-gui-v2/components/smartsheet/Grid.vue

@ -51,7 +51,7 @@ const {
loadData, loadData,
paginationData, paginationData,
formattedData: data, formattedData: data,
updateRowProperty, updateOrSaveRow,
changePage, changePage,
addEmptyRow, addEmptyRow,
selectedRows, selectedRows,
@ -111,7 +111,12 @@ if (meta) useProvideColumnCreateStore(meta)
// }) // })
// reset context menu target on hide // reset context menu target on hide
watch(contextMenu, () => (contextMenuTarget.value = null)) watch(contextMenu, () => {
if(!contextMenu.value) {
contextMenuTarget.value = false
}
})
</script> </script>
<template> <template>
@ -148,15 +153,15 @@ watch(contextMenu, () => (contextMenuTarget.value = null))
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<tr v-for="({ row, rowMeta }, rowIndex) in data" :key="rowIndex" class="nc-grid-row group"> <tr v-for="(row, rowIndex) in data" :key="rowIndex" class="nc-grid-row group">
<td key="row-index" class="caption nc-grid-cell"> <td key="row-index" class="caption nc-grid-cell">
<div class="align-center flex w-[80px]"> <div class="align-center flex w-[80px]">
<div class="group-hover:hidden" :class="{ hidden: rowMeta.selected }">{{ rowIndex + 1 }}</div> <div class="group-hover:hidden" :class="{ hidden: row.rowMeta.selected }">{{ rowIndex + 1 }}</div>
<div <div
:class="{ hidden: !rowMeta.selected, flex: rowMeta.selected }" :class="{ hidden: !row.rowMeta.selected, flex: row.rowMeta.selected }"
class="group-hover:flex w-full align-center" class="group-hover:flex w-full align-center"
> >
<a-checkbox v-model:checked="rowMeta.selected" /> <a-checkbox v-model:checked="row.rowMeta.selected" />
<span class="flex-1" /> <span class="flex-1" />
<MdiArrowExpandIcon class="text-sm text-pink hidden group-hover:inline-block" /> <MdiArrowExpandIcon class="text-sm text-pink hidden group-hover:inline-block" />
</div> </div>
@ -174,14 +179,14 @@ watch(contextMenu, () => (contextMenuTarget.value = null))
@dblclick="editEnabled = true" @dblclick="editEnabled = true"
@contextmenu="contextMenuTarget = { row: rowIndex, col: colIndex }" @contextmenu="contextMenuTarget = { row: rowIndex, col: colIndex }"
> >
<SmartsheetVirtualCell v-if="isVirtualCol(columnObj)" v-model="row[columnObj.title]" :column="columnObj" /> <SmartsheetVirtualCell v-if="isVirtualCol(columnObj)" v-model="row.row[columnObj.title]" :column="columnObj" />
<SmartsheetCell <SmartsheetCell
v-else v-else
v-model="row[columnObj.title]" v-model="row.row[columnObj.title]"
:column="columnObj" :column="columnObj"
:edit-enabled="editEnabled && selected.col === colIndex && selected.row === rowIndex" :edit-enabled="editEnabled && selected.col === colIndex && selected.row === rowIndex"
@update:model-value="updateRowProperty(row, columnObj.title)" @update:model-value="updateOrSaveRow(row, columnObj.title)"
/> />
</td> </td>
</tr> </tr>

7
packages/nc-gui-v2/composables/useViewData.ts

@ -41,6 +41,12 @@ export function useViewData(
paginationData.value = response.pageInfo paginationData.value = response.pageInfo
} }
const updateOrSaveRow = async (row: Row, property: string) => {
if(row.rowMeta.new){
insertRow(row.row, formattedData.value.indexOf(row))
}
}
const updateRowProperty = async (row: Record<string, any>, property: string) => { const updateRowProperty = async (row: Record<string, any>, property: string) => {
try { try {
const id = meta?.value?.columns const id = meta?.value?.columns
@ -219,5 +225,6 @@ export function useViewData(
selectedRows, selectedRows,
deleteRow, deleteRow,
deleteSelectedRows, deleteSelectedRows,
updateOrSaveRow
} }
} }

Loading…
Cancel
Save