From 46b079497aa86a119617770d4664ebc34497c5a6 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Thu, 27 Apr 2023 10:03:23 +0100 Subject: [PATCH] Use 'high-low' nomenclature for numerical columns in grid sort button --- .../grid/controls/SortButton.svelte | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/packages/frontend-core/src/components/grid/controls/SortButton.svelte b/packages/frontend-core/src/components/grid/controls/SortButton.svelte index 26eba050bf..bd75249216 100644 --- a/packages/frontend-core/src/components/grid/controls/SortButton.svelte +++ b/packages/frontend-core/src/components/grid/controls/SortButton.svelte @@ -3,16 +3,13 @@ import { ActionButton, Popover, Select } from "@budibase/bbui" const { sort, columns, stickyColumn } = getContext("grid") - const orderOptions = [ - { label: "A-Z", value: "ascending" }, - { label: "Z-A", value: "descending" }, - ] let open = false let anchor $: columnOptions = getColumnOptions($stickyColumn, $columns) $: checkValidSortColumn($sort.column, $stickyColumn, $columns) + $: orderOptions = getOrderOptions($sort.column, columnOptions) const getColumnOptions = (stickyColumn, columns) => { let options = [] @@ -20,6 +17,7 @@ options.push({ label: stickyColumn.label || stickyColumn.name, value: stickyColumn.name, + type: stickyColumn.schema?.type, }) } return [ @@ -27,10 +25,25 @@ ...columns.map(col => ({ label: col.label || col.name, value: col.name, + type: col.schema?.type, })), ] } + const getOrderOptions = (column, columnOptions) => { + const type = columnOptions.find(col => col.value === column)?.type + return [ + { + label: type === "number" ? "Low-high" : "A-Z", + value: "ascending", + }, + { + label: type === "number" ? "High-low" : "Z-A", + value: "descending", + }, + ] + } + const updateSortColumn = e => { sort.update(state => ({ ...state,