Only autosort columns when custom columns are not specified
This commit is contained in:
parent
dceebb0fc9
commit
f45715d61b
|
@ -28,6 +28,7 @@
|
||||||
export let editColumnTitle = "Edit"
|
export let editColumnTitle = "Edit"
|
||||||
export let customRenderers = []
|
export let customRenderers = []
|
||||||
export let disableSorting = false
|
export let disableSorting = false
|
||||||
|
export let autoSortColumns = true
|
||||||
|
|
||||||
const dispatch = createEventDispatcher()
|
const dispatch = createEventDispatcher()
|
||||||
rowCount = 8
|
rowCount = 8
|
||||||
|
@ -46,7 +47,7 @@
|
||||||
let loaded = false
|
let loaded = false
|
||||||
$: schema = fixSchema(schema)
|
$: schema = fixSchema(schema)
|
||||||
$: if (!loading) loaded = true
|
$: if (!loading) loaded = true
|
||||||
$: fields = getFields(schema, showAutoColumns)
|
$: fields = getFields(schema, showAutoColumns, autoSortColumns)
|
||||||
$: rows = fields?.length ? data || [] : []
|
$: rows = fields?.length ? data || [] : []
|
||||||
$: visibleRowCount = getVisibleRowCount(loaded, height, rows.length, rowCount)
|
$: visibleRowCount = getVisibleRowCount(loaded, height, rows.length, rowCount)
|
||||||
$: contentStyle = getContentStyle(visibleRowCount, rowCount)
|
$: contentStyle = getContentStyle(visibleRowCount, rowCount)
|
||||||
|
@ -162,14 +163,14 @@
|
||||||
return name || ""
|
return name || ""
|
||||||
}
|
}
|
||||||
|
|
||||||
const getFields = (schema, showAutoColumns) => {
|
const getFields = (schema, showAutoColumns, autoSortColumns) => {
|
||||||
let columns = []
|
let columns = []
|
||||||
let autoColumns = []
|
let autoColumns = []
|
||||||
Object.entries(schema || {}).forEach(([field, fieldSchema]) => {
|
Object.entries(schema || {}).forEach(([field, fieldSchema]) => {
|
||||||
if (!field || !fieldSchema) {
|
if (!field || !fieldSchema) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (!fieldSchema?.autocolumn) {
|
if (!autoSortColumns || !fieldSchema?.autocolumn) {
|
||||||
columns.push(fieldSchema)
|
columns.push(fieldSchema)
|
||||||
} else if (showAutoColumns) {
|
} else if (showAutoColumns) {
|
||||||
autoColumns.push(fieldSchema)
|
autoColumns.push(fieldSchema)
|
||||||
|
|
|
@ -87,6 +87,9 @@
|
||||||
if (field?.displayName) {
|
if (field?.displayName) {
|
||||||
newSchema[columnName].displayName = field?.displayName
|
newSchema[columnName].displayName = field?.displayName
|
||||||
}
|
}
|
||||||
|
if (field?.width) {
|
||||||
|
newSchema[columnName].width = field?.width
|
||||||
|
}
|
||||||
})
|
})
|
||||||
return newSchema
|
return newSchema
|
||||||
}
|
}
|
||||||
|
@ -125,6 +128,7 @@
|
||||||
allowEditColumns={false}
|
allowEditColumns={false}
|
||||||
showAutoColumns={true}
|
showAutoColumns={true}
|
||||||
disableSorting
|
disableSorting
|
||||||
|
autoSortColumns={!columns.length}
|
||||||
on:sort={onSort}
|
on:sort={onSort}
|
||||||
on:click={onClick}
|
on:click={onClick}
|
||||||
>
|
>
|
||||||
|
|
Loading…
Reference in New Issue