Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 5 commits into from
Aug 9, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions src/runtime/components/data/Table.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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-data-cell-value="getDataCellValue">
vladyslav-mikhieiev marked this conversation as resolved.
Show resolved Hide resolved
{{ getDataCellValue(row, column.key) }}
</slot>
</td>
</tr>
Expand All @@ -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
Expand Down Expand Up @@ -231,6 +230,10 @@ export default defineComponent({
}
}

const getDataCellValue = (row: Object, rowKey: string | Array<string>) => {
return get(row, rowKey, 'Failed to get cell value')
}

return {
// eslint-disable-next-line vue/no-dupe-keys
ui,
Expand All @@ -247,7 +250,8 @@ export default defineComponent({
isSelected,
onSort,
onSelect,
onChange
onChange,
getDataCellValue
}
}
})
Expand Down