expand table for more info

This commit is contained in:
lightling 2025-03-03 23:10:47 -05:00
parent 0a9e4ebbd4
commit 72c20bde7f
Signed by: lightling
GPG key ID: F1F29650D537C773

View file

@ -1,5 +1,5 @@
<script setup lang="ts"> <script setup lang="ts">
import { ref } from 'vue' import { computed, ref } from 'vue'
import { v7 as uuidv7 } from 'uuid' import { v7 as uuidv7 } from 'uuid'
import Button from 'primevue/button' import Button from 'primevue/button'
import DataTable from 'primevue/datatable' import DataTable from 'primevue/datatable'
@ -22,8 +22,10 @@ const emits = defineEmits<{
}>() }>()
const model = defineModel<DataRow[]>({ required: true }) const model = defineModel<DataRow[]>({ required: true })
const editingRows = ref<DataRow[]>([]) const editingRows = ref<DataRow[]>([])
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 onRowEditSave = (event: { newData: any, index: number }) => { const onRowEditSave = (event: { newData: any, index: number }) => {
let { newData, index } = event let { newData, index } = event
@ -93,17 +95,25 @@ ImageEditor(
DataTable.data-editor( DataTable.data-editor(
@row-edit-save='onRowEditSave' @row-edit-save='onRowEditSave'
v-model:editingRows='editingRows' v-model:editingRows='editingRows'
v-model:expandedRows='expandedRows'
:value='model' :value='model'
editMode='row' editMode='row'
tableStyle='min-width: 50rem' tableStyle='min-width: 50rem'
v-if='model.length > 0' v-if='model.length > 0'
) )
Column(
expander
style='width:5rem;'
)
Column( Column(
v-for='col of columns' v-for='col of columns'
:key='col.name' :key='col.name'
:field='col.name' :field='col.name'
:header='col.name' :header='col.name'
style='width:5rem;' :class=`{
"image-column": col.type === "image",
"other-column": col.type !== "image",
}`
) )
template( template(
#body='slotProps' #body='slotProps'
@ -144,7 +154,6 @@ DataTable.data-editor(
) )
InputText( InputText(
v-model='slotProps.data[slotProps.field]' v-model='slotProps.data[slotProps.field]'
fluid
) )
Column( Column(
rowEditor rowEditor
@ -198,6 +207,28 @@ DataTable.data-editor(
slotProps.editorCancelCallback(e) slotProps.editorCancelCallback(e)
}` }`
) )
template(
#expansion='slotProps'
)
.info
p _id: {{ slotProps.data['_id'] }}
.info(
v-for='(column, field) in columnsByKey'
)
p.empty(
v-if='!slotProps.data[field]'
) {{ field }} is empty
.info-image(
v-else-if='column.type === "image"'
)
p Image
Image(
:src='slotProps.data[field].src'
preview
)
p(
v-else
) {{ field }}: {{ slotProps.data[field] }}
p( p(
v-else v-else
) There are no items yet! ) There are no items yet!
@ -210,10 +241,23 @@ Button(
</template> </template>
<style scoped lang="sass"> <style scoped lang="sass">
:deep(tr > td)
height: 100%
:deep(.image-column)
width: 25vw
:deep(.other-column)
max-width: 0
:deep(.p-image) :deep(.p-image)
img img
max-width: 16rem max-width: 100%
max-height: 8rem
:deep(td:last-of-type) :deep(td:last-of-type)
display: flex padding-left: 0
padding-left: 8px button:first-of-type
margin-left: -16px
.info :deep(.p-image) img
max-width: 16rem
max-height: 16rem
p.empty
font-style: italic
</style> </style>