feat(Table): support nested keys in columns (#503)

Co-authored-by: Benjamin Canac <canacb1@gmail.com>
This commit is contained in:
Vladyslav
2023-08-09 11:56:10 +03:00
committed by Benjamin Canac
parent 74f4903836
commit 858886a852
2 changed files with 10 additions and 6 deletions

View File

@@ -55,8 +55,8 @@
</td>
<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]">
<slot :name="`${column.key}-data`" :column="column" :row="row" :index="index">
{{ row[column.key] }}
<slot :name="`${column.key}-data`" :column="column" :row="row" :index="index" :get-row-data="(defaultValue: any) => getRowData(row, column.key, defaultValue)">
{{ getRowData(row, column.key) }}
</slot>
</td>
</tr>
@@ -69,9 +69,8 @@
<script lang="ts">
import { ref, computed, defineComponent, toRaw } from 'vue'
import type { PropType } from 'vue'
import { capitalize, orderBy } from 'lodash-es'
import { capitalize, orderBy, omit, get } from 'lodash-es'
import { defu } from 'defu'
import { omit } from 'lodash-es'
import type { Button } from '../../types/button'
import { useAppConfig } from '#imports'
// TODO: Remove
@@ -231,6 +230,10 @@ export default defineComponent({
}
}
function getRowData (row: Object, rowKey: string | string[], defaultValue: any = 'Failed to get cell value') {
return get(row, rowKey, defaultValue)
}
return {
// eslint-disable-next-line vue/no-dupe-keys
ui,
@@ -247,7 +250,8 @@ export default defineComponent({
isSelected,
onSort,
onSelect,
onChange
onChange,
getRowData
}
}
})