1
0
Fork 0
mirror of synced 2024-07-14 18:55:45 +12:00

Use 'high-low' nomenclature for numerical columns in grid sort button

This commit is contained in:
Andrew Kingston 2023-04-27 10:03:23 +01:00
parent e239d1e559
commit 46b079497a

View file

@ -3,16 +3,13 @@
import { ActionButton, Popover, Select } from "@budibase/bbui" import { ActionButton, Popover, Select } from "@budibase/bbui"
const { sort, columns, stickyColumn } = getContext("grid") const { sort, columns, stickyColumn } = getContext("grid")
const orderOptions = [
{ label: "A-Z", value: "ascending" },
{ label: "Z-A", value: "descending" },
]
let open = false let open = false
let anchor let anchor
$: columnOptions = getColumnOptions($stickyColumn, $columns) $: columnOptions = getColumnOptions($stickyColumn, $columns)
$: checkValidSortColumn($sort.column, $stickyColumn, $columns) $: checkValidSortColumn($sort.column, $stickyColumn, $columns)
$: orderOptions = getOrderOptions($sort.column, columnOptions)
const getColumnOptions = (stickyColumn, columns) => { const getColumnOptions = (stickyColumn, columns) => {
let options = [] let options = []
@ -20,6 +17,7 @@
options.push({ options.push({
label: stickyColumn.label || stickyColumn.name, label: stickyColumn.label || stickyColumn.name,
value: stickyColumn.name, value: stickyColumn.name,
type: stickyColumn.schema?.type,
}) })
} }
return [ return [
@ -27,10 +25,25 @@
...columns.map(col => ({ ...columns.map(col => ({
label: col.label || col.name, label: col.label || col.name,
value: 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 => { const updateSortColumn = e => {
sort.update(state => ({ sort.update(state => ({
...state, ...state,