diff --git a/src/runtime/components/data/Table.vue b/src/runtime/components/data/Table.vue index ac417f7bcb..07d1e4eaca 100644 --- a/src/runtime/components/data/Table.vue +++ b/src/runtime/components/data/Table.vue @@ -18,7 +18,7 @@ :class="[ui.th.base, ui.th.padding, ui.th.color, ui.th.font, ui.th.size, column.key === 'select' && ui.checkbox.padding, column.class]" :aria-sort="getAriaSort(column)" > - + - + props.columns ?? Object.keys(props.rows[0] ?? {}).map(key => ({ key, label: upperFirst(key), sortable: false, class: undefined, sort: defaultSort }) as TableColumn)) + const columns = computed(() => { + const defaultColumns = props.columns ?? ( + Object.keys(props.rows[0]).map(key => ({ + key, + label: upperFirst(key), + sortable: false, + class: undefined, + sort: defaultSort + })) + ) as TableColumn[] + + const hasColumnSelect = defaultColumns.find(v => v.key === 'select') + + if (hasColumnSelect || !props.modelValue) { + return defaultColumns + } + + return [{ + key: 'select', + sortable: false, + class: undefined, + sort: defaultSort + }, ...defaultColumns] + }) const sort = useVModel(props, 'sort', emit, { passive: true, defaultValue: defu({}, props.sort, { column: null, direction: 'asc' }) }) const expand = useVModel(props, 'expand', emit, { @@ -435,13 +458,6 @@ export default defineComponent({ return expand.value?.openedRows ? expand.value.openedRows.some(openedRow => compare(openedRow, row)) : false } - function shouldRenderColumnInFirstPlace(index: number, key: string) { - if (!props.columns) { - return index === 0 - } - return index === 0 && !props.columns.find(col => col.key === key) - } - function toggleOpened(row: TableRow) { expand.value = { openedRows: isExpanded(row) ? expand.value.openedRows.filter(v => !compare(v, row)) : props.multipleExpand ? [...expand.value.openedRows, row] : [row], @@ -502,7 +518,6 @@ export default defineComponent({ toggleOpened, getAriaSort, isExpanded, - shouldRenderColumnInFirstPlace, retriggerSlot } }