From 1bb2c285ac5bbc94380f87f4aca930ece85edfa4 Mon Sep 17 00:00:00 2001 From: Pranav C Date: Thu, 6 Oct 2022 13:17:45 +0530 Subject: [PATCH] feat(gui): scroll to the active cell on active cell change Signed-off-by: Pranav C --- .../nc-gui/components/smartsheet/Grid.vue | 311 +++++++++--------- 1 file changed, 164 insertions(+), 147 deletions(-) diff --git a/packages/nc-gui/components/smartsheet/Grid.vue b/packages/nc-gui/components/smartsheet/Grid.vue index 0a101e3946..3e773052f9 100644 --- a/packages/nc-gui/components/smartsheet/Grid.vue +++ b/packages/nc-gui/components/smartsheet/Grid.vue @@ -327,6 +327,22 @@ watch( }, { immediate: true }, ) + +const tbodyEl = ref() + +watch([() => selected.row, () => selected.col], ([row, col]) => { + if (row !== null && col !== null) { + // get active cell + const td = tbodyEl.value?.querySelectorAll('tr')[row]?.querySelectorAll('td')[col + 1] + if (!td) return + // scroll into the active cell + td.scrollIntoView({ + behavior: 'smooth', + block: 'end', + inline: 'end', + }) + } +})