Only autosort columns when custom columns are not specified

This commit is contained in:
Andrew Kingston 2022-02-18 12:35:39 +00:00
parent dceebb0fc9
commit f45715d61b
2 changed files with 8 additions and 3 deletions

View File

@ -28,6 +28,7 @@
export let editColumnTitle = "Edit"
export let customRenderers = []
export let disableSorting = false
export let autoSortColumns = true
const dispatch = createEventDispatcher()
rowCount = 8
@ -46,7 +47,7 @@
let loaded = false
$: schema = fixSchema(schema)
$: if (!loading) loaded = true
$: fields = getFields(schema, showAutoColumns)
$: fields = getFields(schema, showAutoColumns, autoSortColumns)
$: rows = fields?.length ? data || [] : []
$: visibleRowCount = getVisibleRowCount(loaded, height, rows.length, rowCount)
$: contentStyle = getContentStyle(visibleRowCount, rowCount)
@ -162,14 +163,14 @@
return name || ""
}
const getFields = (schema, showAutoColumns) => {
const getFields = (schema, showAutoColumns, autoSortColumns) => {
let columns = []
let autoColumns = []
Object.entries(schema || {}).forEach(([field, fieldSchema]) => {
if (!field || !fieldSchema) {
return
}
if (!fieldSchema?.autocolumn) {
if (!autoSortColumns || !fieldSchema?.autocolumn) {
columns.push(fieldSchema)
} else if (showAutoColumns) {
autoColumns.push(fieldSchema)

View File

@ -87,6 +87,9 @@
if (field?.displayName) {
newSchema[columnName].displayName = field?.displayName
}
if (field?.width) {
newSchema[columnName].width = field?.width
}
})
return newSchema
}
@ -125,6 +128,7 @@
allowEditColumns={false}
showAutoColumns={true}
disableSorting
autoSortColumns={!columns.length}
on:sort={onSort}
on:click={onClick}
>