Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisbbreuer committed May 19, 2022
2 parents 55e76fa + 739667d commit 50a7340
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 4 deletions.
8 changes: 7 additions & 1 deletion src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,13 @@ import { Table as TableV2 } from './main'
actions="Info Icon"
per-page="10"
checkable="true"
/>
>
<template #part_name="partNameProps">
<div v-for="(part, x) in partNameProps.value" :key="x" class="text-yellow-600">
{{ part }}
</div>
</template>
</TableV2>
</Suspense>

<Suspense>
Expand Down
12 changes: 11 additions & 1 deletion src/components/Table.vue
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ const cols = $computed((): string[] => {
return columns
})
const sortDirections = $computed((): string[] => {
if (isString(sorts))
return sorts.split(',').map(col => col.trim())
Expand Down Expand Up @@ -106,6 +107,10 @@ table.value.perPage = itemsPerPage
table.value.actions = actions
table.value.actionable = actionable
table.value.checkable = checkable
function colName(col: string) {
return col.split(':')[0].trim()
}
</script>

<template>
Expand All @@ -116,7 +121,12 @@ table.value.checkable = checkable
<div class="shadow ring-black ring-1 ring-opacity-5 overflow-hidden md:rounded-lg">
<table class="divide-y min-w-full divide-gray-300">
<TableHead />
<TableBody />
<TableBody>
<template v-for="(col, x) in cols" :key="x" #[colName(col)]="tableBodyData">
<!-- {{ tableBodyData }} -->
<slot :name="colName(col)" :value="tableBodyData.tableRowData" />
</template>
</TableBody>
</table>
</div>
</div>
Expand Down
11 changes: 10 additions & 1 deletion src/components/TableBody.vue
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
<script setup lang="ts">
import { isString } from '@vueuse/core'
// eslint-disable-next-line no-console
console.log('TableBody.vue')
const { table } = $(await useTable())
function colName(col: any) {
return col.split(':')[0].trim()
}
</script>

<template>
<tbody class="divide-y bg-white divide-gray-200">
<TableRow v-for="(hit, index) in table.results?.hits" :key="index" :hit="hit" />
<TableRow v-for="(hit, index) in table.results?.hits" :key="index" :hit="hit">
<template v-for="(col, x) in table.columns" :key="x" #[colName(col)]="tableRowData">
<slot :name="colName(col)" :table-row-data="tableRowData.colData" />
</template>
</TableRow>
</tbody>
</template>
8 changes: 7 additions & 1 deletion src/components/TableRow.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ function generateValue(hit: any, col: any) {
return JSON.parse(hit[col])
}
function colName(col: any) {
return col.split(':')[0].trim()
}
</script>

<template>
Expand All @@ -31,7 +35,9 @@ function generateValue(hit: any, col: any) {
</span>

<span v-else>
{{ generateValue(hit, col) }}
<slot :name="colName(col)" :col-data="generateValue(hit, col)">
{{ generateValue(hit, col) }}
</slot>
</span>
</td>
</tr>
Expand Down

0 comments on commit 50a7340

Please sign in to comment.