Refresh view data when showing hidden columns in order to populate new cells
This commit is contained in:
parent
1382290116
commit
6a7e0d2d31
|
@ -3,7 +3,7 @@
|
||||||
import { ActionButton, Popover, Toggle, Icon } from "@budibase/bbui"
|
import { ActionButton, Popover, Toggle, Icon } from "@budibase/bbui"
|
||||||
import { getColumnIcon } from "../lib/utils"
|
import { getColumnIcon } from "../lib/utils"
|
||||||
|
|
||||||
const { columns, stickyColumn } = getContext("grid")
|
const { columns, stickyColumn, dispatch } = getContext("grid")
|
||||||
|
|
||||||
let open = false
|
let open = false
|
||||||
let anchor
|
let anchor
|
||||||
|
@ -11,33 +11,36 @@
|
||||||
$: anyHidden = $columns.some(col => !col.visible)
|
$: anyHidden = $columns.some(col => !col.visible)
|
||||||
$: text = getText($columns)
|
$: text = getText($columns)
|
||||||
|
|
||||||
const toggleVisibility = (column, visible) => {
|
const toggleVisibility = async (column, visible) => {
|
||||||
columns.update(state => {
|
columns.update(state => {
|
||||||
const index = state.findIndex(col => col.name === column.name)
|
const index = state.findIndex(col => col.name === column.name)
|
||||||
state[index].visible = visible
|
state[index].visible = visible
|
||||||
return state.slice()
|
return state.slice()
|
||||||
})
|
})
|
||||||
columns.actions.saveChanges()
|
await columns.actions.saveChanges()
|
||||||
|
dispatch(visible ? "show-column" : "hide-column")
|
||||||
}
|
}
|
||||||
|
|
||||||
const showAll = () => {
|
const showAll = async () => {
|
||||||
columns.update(state => {
|
columns.update(state => {
|
||||||
return state.map(col => ({
|
return state.map(col => ({
|
||||||
...col,
|
...col,
|
||||||
visible: true,
|
visible: true,
|
||||||
}))
|
}))
|
||||||
})
|
})
|
||||||
columns.actions.saveChanges()
|
await columns.actions.saveChanges()
|
||||||
|
dispatch("show-column")
|
||||||
}
|
}
|
||||||
|
|
||||||
const hideAll = () => {
|
const hideAll = async () => {
|
||||||
columns.update(state => {
|
columns.update(state => {
|
||||||
return state.map(col => ({
|
return state.map(col => ({
|
||||||
...col,
|
...col,
|
||||||
visible: false,
|
visible: false,
|
||||||
}))
|
}))
|
||||||
})
|
})
|
||||||
columns.actions.saveChanges()
|
await columns.actions.saveChanges()
|
||||||
|
dispatch("hide-column")
|
||||||
}
|
}
|
||||||
|
|
||||||
const getText = columns => {
|
const getText = columns => {
|
||||||
|
|
|
@ -84,7 +84,7 @@ export const createActions = context => {
|
||||||
}
|
}
|
||||||
|
|
||||||
export const initialise = context => {
|
export const initialise = context => {
|
||||||
const { definition, datasource, sort, rows, filter } = context
|
const { definition, datasource, sort, rows, filter, subscribe } = context
|
||||||
|
|
||||||
// Keep sort and filter state in line with the view definition
|
// Keep sort and filter state in line with the view definition
|
||||||
definition.subscribe($definition => {
|
definition.subscribe($definition => {
|
||||||
|
@ -133,4 +133,13 @@ export const initialise = context => {
|
||||||
await rows.actions.refreshData()
|
await rows.actions.refreshData()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// When hidden we show columns, we need to refresh data in order to fetch
|
||||||
|
// values for those columns
|
||||||
|
subscribe("show-column", async () => {
|
||||||
|
if (get(datasource)?.type !== "viewV2") {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
await rows.actions.refreshData()
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue