diff --git a/packages/nc-gui-v2/components/smartsheet/sidebar/MenuTop.vue b/packages/nc-gui-v2/components/smartsheet/sidebar/MenuTop.vue index 0efe9ed656..b46542022a 100644 --- a/packages/nc-gui-v2/components/smartsheet/sidebar/MenuTop.vue +++ b/packages/nc-gui-v2/components/smartsheet/sidebar/MenuTop.vue @@ -78,21 +78,21 @@ function initializeSortable(el: HTMLElement) { const currentItem: Record = views.value[oldIndex] // get items meta of before and after the moved item - const itemBefore: Record = views.value[newIndex] - const itemAfter: Record = views.value[newIndex + 1] + const nextItem: Record = views.value[newIndex] + const previousItem: Record = views.value[newIndex + 1] let nextOrder: number // set new order value based on the new order of the items if (views.value.length - 1 === newIndex) { - nextOrder = itemBefore.order + 1 + nextOrder = parseFloat(nextItem.order) + 1 } else if (newIndex === 0) { - nextOrder = itemAfter.order / 2 + nextOrder = parseFloat(nextItem.order) / 2 } else { - nextOrder = (itemBefore.order + itemAfter.order) / 2 + nextOrder = (parseFloat(nextItem.order) + parseFloat(previousItem.order)) / 2 } - await api.dbView.update(currentItem.id, { order: nextOrder.toString() }) + await api.dbView.update(currentItem.id, { order: !isNaN(Number(nextOrder)) ? nextOrder.toString() : oldIndex.toString() }) }, animation: 150, })