support secondary fields

This commit is contained in:
lightling 2025-03-04 21:21:34 -05:00
parent 6f4790c301
commit 994b61a454
Signed by: lightling
GPG key ID: F1F29650D537C773
3 changed files with 29 additions and 13 deletions

View file

@ -16,6 +16,7 @@ export interface Image {
export interface Column { export interface Column {
name: string name: string
type: FieldType type: FieldType
secondary?: boolean
} }
export type Columns = Column[] export type Columns = Column[]

View file

@ -26,6 +26,7 @@ const expandedRows = ref<DataRow[]>([])
const editingImage = ref(false) const editingImage = ref(false)
const editingImageRow = ref(null as EditingRow | null) const editingImageRow = ref(null as EditingRow | null)
const columnsByKey = computed(() => Object.assign({}, ...props.columns.map(c => ({[c.name]: c})))) const columnsByKey = computed(() => Object.assign({}, ...props.columns.map(c => ({[c.name]: c}))))
const columnsPrimary = computed(() => props.columns.filter(column => !column.secondary))
const onRowEditSave = (event: { newData: any, index: number }) => { const onRowEditSave = (event: { newData: any, index: number }) => {
let { newData, index } = event let { newData, index } = event
@ -106,7 +107,7 @@ DataTable.data-editor(
style='width:5rem;' style='width:5rem;'
) )
Column( Column(
v-for='col of columns' v-for='col of columnsPrimary'
:key='col.name' :key='col.name'
:field='col.name' :field='col.name'
:header='col.name' :header='col.name'
@ -170,9 +171,7 @@ DataTable.data-editor(
rounded rounded
severity='secondary' severity='secondary'
variant='text' variant='text'
:onClick=`(e) => { @click='slotProps.editorInitCallback'
slotProps.editorInitCallback(e)
}`
) )
Button( Button(
icon='pi pi-trash' icon='pi pi-trash'
@ -180,9 +179,7 @@ DataTable.data-editor(
rounded rounded
severity='danger' severity='danger'
variant='text' variant='text'
:onClick=`(e) => { :onClick='(e) => onDeleteRow(e, slotProps)'
onDeleteRow(e, slotProps)
}`
) )
template( template(
#editor='slotProps' #editor='slotProps'
@ -193,9 +190,7 @@ DataTable.data-editor(
rounded rounded
severity='secondary' severity='secondary'
variant='text' variant='text'
:onClick=`(e) => { @click='slotProps.editorSaveCallback'
slotProps.editorSaveCallback(e)
}`
) )
Button( Button(
icon='pi pi-times' icon='pi pi-times'
@ -203,9 +198,7 @@ DataTable.data-editor(
rounded rounded
severity='secondary' severity='secondary'
variant='text' variant='text'
:onClick=`(e) => { @click'slotProps.editorCancelCallback(e)'
slotProps.editorCancelCallback(e)
}`
) )
template( template(
#expansion='slotProps' #expansion='slotProps'

View file

@ -2,6 +2,7 @@
import { ref } from 'vue' import { ref } from 'vue'
import { v1 as uuidv1 } from 'uuid' import { v1 as uuidv1 } from 'uuid'
import Button from 'primevue/button' import Button from 'primevue/button'
import Checkbox from 'primevue/checkbox'
import DataTable from 'primevue/datatable' import DataTable from 'primevue/datatable'
import Column from 'primevue/column' import Column from 'primevue/column'
import InputText from 'primevue/inputtext' import InputText from 'primevue/inputtext'
@ -82,6 +83,27 @@ DataTable.field-editor(
v-model='data[field]' v-model='data[field]'
:options='FieldTypes' :options='FieldTypes'
) )
Column(
field='secondary'
header='Secondary'
)
template(
#body='slotProps'
)
Checkbox(
v-model='slotProps.data.secondary'
:name='`${slotProps.data.name} is secondary`'
binary
disabled
)
template(
#editor='slotProps'
)
Checkbox(
v-model='slotProps.data.secondary'
:name='`${slotProps.data.name} is secondary`'
binary
)
Column( Column(
rowEditor rowEditor
header='Actions' header='Actions'