|
18 | 18 | :class="[ui.th.base, ui.th.padding, ui.th.color, ui.th.font, ui.th.size, column.key === 'select' && ui.checkbox.padding, column.class]"
|
19 | 19 | :aria-sort="getAriaSort(column)"
|
20 | 20 | >
|
21 |
| - <slot v-if="!singleSelect && modelValue && (column.key === 'select' || shouldRenderColumnInFirstPlace(index, 'select'))" name="select-header" :indeterminate="indeterminate" :checked="isAllRowChecked" :change="onChange"> |
| 21 | + <slot v-if="!singleSelect && modelValue && column.key === 'select'" name="select-header" :indeterminate="indeterminate" :checked="isAllRowChecked" :change="onChange"> |
22 | 22 | <UCheckbox
|
23 | 23 | :model-value="isAllRowChecked"
|
24 | 24 | :indeterminate="indeterminate"
|
|
93 | 93 | />
|
94 | 94 | </td>
|
95 | 95 | <td v-for="(column, subIndex) in columns" :key="subIndex" :class="[ui.td.base, ui.td.padding, ui.td.color, ui.td.font, ui.td.size, column?.rowClass, row[column.key]?.class, column.key === 'select' && ui.checkbox.padding]">
|
96 |
| - <slot v-if="modelValue && (column.key === 'select' || shouldRenderColumnInFirstPlace(subIndex, 'select')) " name="select-data" :checked="isSelected(row)" :change="(ev: boolean) => onChangeCheckbox(ev, row)"> |
| 96 | + <slot v-if="modelValue && column.key === 'select' " name="select-data" :checked="isSelected(row)" :change="(ev: boolean) => onChangeCheckbox(ev, row)"> |
97 | 97 | <UCheckbox
|
98 | 98 | :model-value="isSelected(row)"
|
99 | 99 | v-bind="ui.default.checkbox"
|
@@ -274,7 +274,30 @@ export default defineComponent({
|
274 | 274 | setup(props, { emit, attrs: $attrs }) {
|
275 | 275 | const { ui, attrs } = useUI('table', toRef(props, 'ui'), config, toRef(props, 'class'))
|
276 | 276 |
|
277 |
| - const columns = computed(() => props.columns ?? Object.keys(props.rows[0] ?? {}).map(key => ({ key, label: upperFirst(key), sortable: false, class: undefined, sort: defaultSort }) as TableColumn)) |
| 277 | + const columns = computed(() => { |
| 278 | + const defaultColumns = props.columns ?? ( |
| 279 | + Object.keys(props.rows[0]).map(key => ({ |
| 280 | + key, |
| 281 | + label: upperFirst(key), |
| 282 | + sortable: false, |
| 283 | + class: undefined, |
| 284 | + sort: defaultSort |
| 285 | + })) |
| 286 | + ) as TableColumn[] |
| 287 | +
|
| 288 | + const hasColumnSelect = defaultColumns.find(v => v.key === 'select') |
| 289 | +
|
| 290 | + if (hasColumnSelect || !props.modelValue) { |
| 291 | + return defaultColumns |
| 292 | + } |
| 293 | +
|
| 294 | + return [{ |
| 295 | + key: 'select', |
| 296 | + sortable: false, |
| 297 | + class: undefined, |
| 298 | + sort: defaultSort |
| 299 | + }, ...defaultColumns] |
| 300 | + }) |
278 | 301 |
|
279 | 302 | const sort = useVModel(props, 'sort', emit, { passive: true, defaultValue: defu({}, props.sort, { column: null, direction: 'asc' }) })
|
280 | 303 | const expand = useVModel(props, 'expand', emit, {
|
@@ -435,13 +458,6 @@ export default defineComponent({
|
435 | 458 | return expand.value?.openedRows ? expand.value.openedRows.some(openedRow => compare(openedRow, row)) : false
|
436 | 459 | }
|
437 | 460 |
|
438 |
| - function shouldRenderColumnInFirstPlace(index: number, key: string) { |
439 |
| - if (!props.columns) { |
440 |
| - return index === 0 |
441 |
| - } |
442 |
| - return index === 0 && !props.columns.find(col => col.key === key) |
443 |
| - } |
444 |
| -
|
445 | 461 | function toggleOpened(row: TableRow) {
|
446 | 462 | expand.value = {
|
447 | 463 | 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({
|
502 | 518 | toggleOpened,
|
503 | 519 | getAriaSort,
|
504 | 520 | isExpanded,
|
505 |
| - shouldRenderColumnInFirstPlace, |
506 | 521 | retriggerSlot
|
507 | 522 | }
|
508 | 523 | }
|
|
0 commit comments