@@ -85,6 +106,14 @@ const props = defineProps({
columns: {
type: Array,
default: () => []
+ },
+ displayColumns: {
+ type: Object,
+ default: () => ({})
+ },
+ wrapColumns: {
+ type: Object,
+ default: () => ({})
}
})
@@ -122,16 +151,24 @@ const sections = computed(() => [
])
// Column preferences storage
+const storageKey = computed(() => `column-preferences-formid-${props.form.id}`)
+
const columnPreferences = useStorage(
- computed(() => props.form ? `column-preferences-formid-${props.form.id}` : null),
+ storageKey.value,
{
display: {},
wrap: {},
widths: {}
+ },
+ localStorage,
+ {
+ onError: (error) => {
+ console.error('Storage error:', error)
+ }
}
)
-const displayColumns = computed({
+const computedDisplayColumns = computed({
get: () => columnPreferences.value.display,
set: (val) => {
columnPreferences.value.display = val
@@ -139,7 +176,7 @@ const displayColumns = computed({
}
})
-const wrapColumns = computed({
+const computedWrapColumns = computed({
get: () => columnPreferences.value.wrap,
set: (val) => {
columnPreferences.value.wrap = val
@@ -164,12 +201,18 @@ function preserveColumnWidths(newColumns, existingColumns = []) {
// Then fallback to form properties
const existing = existingColumns?.find(e => e.id === col.id)
- const width = storedWidth || currentCol?.cell_width || currentCol?.width || existing?.cell_width || existing?.width || col.width || 150
+ // Convert any non-numeric width to default
+ const defaultWidth = 250
+ let width = storedWidth || currentCol?.width || existing?.width || defaultWidth
+
+ // If width is not a number or is 'full', use default width
+ if (typeof width !== 'number' || isNaN(width)) {
+ width = defaultWidth
+ }
return {
...col,
- width,
- cell_width: width
+ width
}
})
}
@@ -187,8 +230,8 @@ watch(() => props.columns, (newColumns) => {
const widths = {}
newColumns.forEach(col => {
- if (col.cell_width) {
- widths[col.id] = col.cell_width
+ if (col.width) {
+ widths[col.id] = col.width
}
})
@@ -199,42 +242,63 @@ watch(() => props.columns, (newColumns) => {
watch(() => props.form, (newForm) => {
if (!newForm) return
- const properties = newForm.properties || []
+ const properties = candidatesProperties.value
const storedPrefs = columnPreferences.value
+ const removedProperties = newForm.removed_properties || []
// Initialize display columns if not set
if (!Object.keys(storedPrefs.display).length) {
+ // Set all non-removed properties to visible by default
properties.forEach((field) => {
storedPrefs.display[field.id] = true
})
+ // Also handle removed properties
+ removedProperties.forEach((field) => {
+ storedPrefs.display[field.id] = false
+ })
}
// Initialize wrap columns if not set
if (!Object.keys(storedPrefs.wrap).length) {
- properties.forEach((field) => {
+ [...properties, ...removedProperties].forEach((field) => {
storedPrefs.wrap[field.id] = false
})
}
+ // Initialize widths if not set
+ if (!Object.keys(storedPrefs.widths).length) {
+ [...properties, ...removedProperties].forEach((field) => {
+ const defaultWidth = 150
+ storedPrefs.widths[field.id] = field.width || defaultWidth
+ })
+ }
+
// Emit initial values
emit('update:displayColumns', storedPrefs.display)
emit('update:wrapColumns', storedPrefs.wrap)
- // Emit initial columns (all visible by default)
- const initialColumns = clonedeep(candidatesProperties.value)
- .concat(props.form?.removed_properties || [])
- .filter((field) => storedPrefs.display[field.id] !== false) // Show all columns by default unless explicitly hidden
+ // Emit initial columns (all non-removed visible by default)
+ const initialColumns = clonedeep(properties)
+ .concat(removedProperties)
+ .filter((field) => storedPrefs.display[field.id] !== false)
// Preserve any existing column widths
- const columnsWithWidths = preserveColumnWidths(initialColumns, props.form.properties)
+ const columnsWithWidths = preserveColumnWidths(initialColumns, properties)
emit('update:columns', columnsWithWidths)
}, { immediate: true })
+function toggleAllColumns(fields, show) {
+ fields.forEach((field) => {
+ computedDisplayColumns.value[field.id] = show
+ })
+ onChangeDisplayColumns()
+}
+
function onChangeDisplayColumns() {
if (!import.meta.client) return
const properties = clonedeep(candidatesProperties.value)
.concat(props.form?.removed_properties || [])
- .filter((field) => displayColumns.value[field.id] === true)
+ .filter((field) => computedDisplayColumns.value[field.id] === true)
// Preserve existing column widths when toggling visibility
const columnsWithWidths = preserveColumnWidths(properties, props.form.properties)
diff --git a/client/components/open/forms/components/FormSubmissions.vue b/client/components/open/forms/components/FormSubmissions.vue
index 9f909f84..0ce4ee01 100644
--- a/client/components/open/forms/components/FormSubmissions.vue
+++ b/client/components/open/forms/components/FormSubmissions.vue
@@ -10,11 +10,14 @@
@@ -225,6 +228,7 @@ export default {
},
onColumnUpdated(columns) {
this.properties = columns
+ this.dataChanged()
},
onUpdateRecord(submission) {
this.recordStore.save(submission)
diff --git a/client/components/open/tables/OpenTable.vue b/client/components/open/tables/OpenTable.vue
index 6fd0df47..76876146 100644
--- a/client/components/open/tables/OpenTable.vue
+++ b/client/components/open/tables/OpenTable.vue
@@ -7,7 +7,7 @@
@@ -18,7 +18,7 @@
:key="col.id"
scope="col"
:allow-resize="allowResize"
- :width="col.cell_width ? col.cell_width + 'px' : 'auto'"
+ :width="col.width ? col.width + 'px' : '150px'"
class="n-table-cell p-0 relative"
@resize-width="resizeCol(col, $event)"
>
@@ -68,7 +68,7 @@
| {
this.internalColumns.forEach((col) => {
- if (!_has(col, "cell_width")) {
+ if (!_has(col, "width")) {
if (
this.allowResize &&
this.internalColumns.length &&
@@ -315,7 +316,7 @@ export default {
resizeCol(col, width) {
if (!this.form) return
const index = this.internalColumns.findIndex((c) => c.id === col.id)
- this.internalColumns[index].cell_width = width
+ this.internalColumns[index].width = width
this.setColumns(this.internalColumns)
this.$nextTick(() => {
this.$emit("resize")
diff --git a/client/components/open/tables/components/OpenSelect.vue b/client/components/open/tables/components/OpenSelect.vue
index 4ba466da..3bfe9bc8 100644
--- a/client/components/open/tables/components/OpenSelect.vue
+++ b/client/components/open/tables/components/OpenSelect.vue
@@ -24,8 +24,14 @@ export default {
components: { OpenTag },
props: {
value: {
- type: Object,
+ type: [String, Object, Array],
+ required: false,
+ default: null
},
+ property: {
+ type: Object,
+ required: true
+ }
},
data() {
@@ -34,10 +40,7 @@ export default {
computed: {
valueIsObject() {
- if (typeof this.value === "object" && this.value !== null) {
- return true
- }
- return false
+ return Array.isArray(this.value) || (typeof this.value === "object" && this.value !== null)
},
},
}
diff --git a/client/components/open/tables/components/OpenText.vue b/client/components/open/tables/components/OpenText.vue
index 783aa457..b86063cb 100644
--- a/client/components/open/tables/components/OpenText.vue
+++ b/client/components/open/tables/components/OpenText.vue
@@ -7,8 +7,9 @@ export default {
components: {},
props: {
value: {
- type: String,
- required: true,
+ type: [String, Number],
+ required: false,
+ default: null
},
},
}
|