1
0
Fork 0
mirror of synced 2024-07-28 09:35:49 +12:00

Add column setting to grid

This commit is contained in:
Andrew Kingston 2023-06-19 17:38:44 +01:00
parent d77b2c6ab1
commit 9d8b5e99af
7 changed files with 33 additions and 11 deletions

View file

@ -36,6 +36,7 @@
allowDeleteRows={!isUsersTable} allowDeleteRows={!isUsersTable}
schemaOverrides={isUsersTable ? userSchemaOverrides : null} schemaOverrides={isUsersTable ? userSchemaOverrides : null}
showAvatars={false} showAvatars={false}
columnWhitelist={["email", "firstName", "lastName"]}
on:updatetable={e => tables.replaceTable(id, e.detail)} on:updatetable={e => tables.replaceTable(id, e.detail)}
> >
<svelte:fragment slot="controls"> <svelte:fragment slot="controls">

View file

@ -5227,9 +5227,8 @@
} }
}, },
"gridblock": { "gridblock": {
"block": true,
"name": "Grid block", "name": "Grid block",
"icon": "Table", "icon": "ViewTable",
"styles": ["size"], "styles": ["size"],
"size": { "size": {
"width": 600, "width": 600,
@ -5244,10 +5243,11 @@
"required": true "required": true
}, },
{ {
"type": "columns", "type": "multifield",
"label": "Columns", "label": "Columns",
"key": "columns", "key": "columnWhitelist",
"dependsOn": "table" "dependsOn": "table",
"placeholder": "All columns"
}, },
{ {
"type": "filter", "type": "filter",

View file

@ -13,6 +13,7 @@
export let initialSortColumn = null export let initialSortColumn = null
export let initialSortOrder = null export let initialSortOrder = null
export let initialRowHeight = null export let initialRowHeight = null
export let columnWhitelist = null
const component = getContext("component") const component = getContext("component")
const { styleable, API, builderStore } = getContext("sdk") const { styleable, API, builderStore } = getContext("sdk")
@ -33,6 +34,7 @@
{initialSortColumn} {initialSortColumn}
{initialSortOrder} {initialSortOrder}
{initialRowHeight} {initialRowHeight}
{columnWhitelist}
showControls={false} showControls={false}
allowExpandRows={false} allowExpandRows={false}
allowSchemaChanges={false} allowSchemaChanges={false}

View file

@ -197,10 +197,12 @@
Move right Move right
</MenuItem> </MenuItem>
<MenuItem <MenuItem
disabled={idx === "sticky"} disabled={idx === "sticky" || !$config.showControls}
icon="VisibilityOff" icon="VisibilityOff"
on:click={hideColumn}>Hide column</MenuItem on:click={hideColumn}
> >
Hide column
</MenuItem>
</Menu> </Menu>
</Popover> </Popover>

View file

@ -33,6 +33,7 @@
export let API = null export let API = null
export let tableId = null export let tableId = null
export let schemaOverrides = null export let schemaOverrides = null
export let columnWhitelist = null
export let allowAddRows = true export let allowAddRows = true
export let allowExpandRows = true export let allowExpandRows = true
export let allowEditRows = true export let allowEditRows = true
@ -76,6 +77,7 @@
$: config.set({ $: config.set({
tableId, tableId,
schemaOverrides, schemaOverrides,
columnWhitelist,
allowAddRows, allowAddRows,
allowExpandRows, allowExpandRows,
allowEditRows, allowEditRows,

View file

@ -131,11 +131,12 @@ export const deriveStores = context => {
} }
export const initialise = context => { export const initialise = context => {
const { table, columns, stickyColumn, schemaOverrides } = context const { table, columns, stickyColumn, schemaOverrides, columnWhitelist } =
context
const schema = derived( const schema = derived(
[table, schemaOverrides], [table, schemaOverrides, columnWhitelist],
([$table, $schemaOverrides]) => { ([$table, $schemaOverrides, $columnWhitelist]) => {
if (!$table?.schema) { if (!$table?.schema) {
return null return null
} }
@ -162,6 +163,16 @@ export const initialise = context => {
} }
} }
}) })
// Apply whitelist if specified
if ($columnWhitelist?.length) {
Object.keys(newSchema).forEach(key => {
if (!$columnWhitelist.includes(key)) {
delete newSchema[key]
}
})
}
return newSchema return newSchema
} }
) )
@ -229,7 +240,7 @@ export const initialise = context => {
} }
stickyColumn.set({ stickyColumn.set({
name: primaryDisplay, name: primaryDisplay,
label: $schema[primaryDisplay].name || primaryDisplay, label: $schema[primaryDisplay].displayName || primaryDisplay,
schema: $schema[primaryDisplay], schema: $schema[primaryDisplay],
width: $schema[primaryDisplay].width || DefaultColumnWidth, width: $schema[primaryDisplay].width || DefaultColumnWidth,
visible: true, visible: true,

View file

@ -11,6 +11,8 @@ export const createStores = context => {
const initialSortOrder = getProp("initialSortOrder") const initialSortOrder = getProp("initialSortOrder")
const initialFilter = getProp("initialFilter") const initialFilter = getProp("initialFilter")
const initialRowHeight = getProp("initialRowHeight") const initialRowHeight = getProp("initialRowHeight")
const schemaOverrides = getProp("schemaOverrides")
const columnWhitelist = getProp("columnWhitelist")
return { return {
config, config,
@ -19,5 +21,7 @@ export const createStores = context => {
initialSortOrder, initialSortOrder,
initialFilter, initialFilter,
initialRowHeight, initialRowHeight,
schemaOverrides,
columnWhitelist,
} }
} }