Repository navigation
feat(Table): add colgroup slot - #7468
mateusznarowski wants to merge 1 commit into
Conversation
|
I also tried using TanStack’s column sizes with the current slot. You can get the visible columns in render order from <script setup lang="ts">
import { computed, useTemplateRef } from 'vue'
import type { TableColumn } from '@nuxt/ui'
const data = [{ order: 101, status: 'Paid', amount: '$42.00' }]
const columns: TableColumn<typeof data[number]>[] = [
{ accessorKey: 'order', header: 'Order', size: 96 },
{ accessorKey: 'status', header: 'Status', size: 112 },
{ accessorKey: 'amount', header: 'Amount', size: 128 }
]
const table = useTemplateRef('table')
const visibleColumns = computed(() => {
const api = table.value?.tableApi
if (!api) return []
return [
...api.getLeftVisibleLeafColumns(),
...api.getCenterVisibleLeafColumns(),
...api.getRightVisibleLeafColumns()
]
})
</script>
<template>
<UTable ref="table" :data="data" :columns="columns">
<template #colgroup>
<colgroup v-if="visibleColumns.length">
<col
v-for="column in visibleColumns"
:key="column.id"
:style="{ width: `${column.getSize()}px` }"
>
</colgroup>
</template>
</UTable>
</template>One small follow-up could be to move that <slot name="colgroup" :columns="visibleColumns" />The caller would keep the same I’ve kept the slot simple in this PR. Do you think exposing |
|
Client output of the apps in
Raw sizes
|
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
commit: |
Merging this PR will improve performance by 41.59%2 warnings
Performance Changes
Tip Curious why performance improved? Comment Comparing Footnotes
|
🔗 Linked issue
Resolves #7399
❓ Type of change
📚 Description
Add an optional
#colgroupslot toUTable, rendered after<caption>and before<thead>.With a fixed table layout, widths on header cells work for simple tables. When the first header row contains a cell that spans multiple columns, a
<colgroup>lets users set a separate width for each column under that shared header.Include a docs example with grouped headers and a test for the slot's placement.
📝 Checklist