Skip to content

Commit

Permalink
feat(table): add option to specify custom class name for column
Browse files Browse the repository at this point in the history
  • Loading branch information
kiaking committed Nov 14, 2022
1 parent a69339a commit a7bca60
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 5 deletions.
18 changes: 16 additions & 2 deletions lib/components/STable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,17 @@ function updateColWidth(key: string, value: string) {
>
<div class="block">
<div class="row">
<STableItem v-for="key in orders" :key="key" :name="key" :width="colWidths[key]">
<STableItem
v-for="key in orders"
:key="key"
:name="key"
:class-name="columns[key].className"
:width="colWidths[key]"
>
<STableColumn
:name="key"
:label="columns[key].label"
:class-name="columns[key].className"
:dropdown="columns[key].dropdown"
@resize="(value) => updateColWidth(key, value)"
/>
Expand All @@ -124,9 +131,16 @@ function updateColWidth(key: string, value: string) {
>
<div class="block">
<div v-for="(record, rIndex) in records" :key="rIndex" class="row">
<STableItem v-for="key in orders" :key="key" :name="key" :width="colWidths[key]">
<STableItem
v-for="key in orders"
:key="key"
:name="key"
:class-name="columns[key].className"
:width="colWidths[key]"
>
<STableCell
:name="key"
:class-name="columns[key].className"
:cell="columns[key].cell"
:value="record[key]"
:record="record"
Expand Down
3 changes: 2 additions & 1 deletion lib/components/STableCell.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import STableCellText from './STableCellText.vue'
defineProps<{
name: string
className?: string
cell?: TableCell
value: any
record: any
Expand All @@ -16,7 +17,7 @@ defineProps<{
</script>

<template>
<div class="STableCell" :class="[`col-${name}`]">
<div class="STableCell" :class="[className, `col-${name}`]">
<STableCellText
v-if="!cell || cell.type === 'text'"
:value="value"
Expand Down
2 changes: 1 addition & 1 deletion lib/components/STableColumn.vue
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ function stopDialogPositionListener() {
</script>

<template>
<div class="STableColumn STableCell" :class="[{ active }, className ?? `col-${name}`]" ref="column">
<div class="STableColumn STableCell" :class="[{ active }, className, `col-${name}`]" ref="column">
<div class="container">
<p class="label">{{ label }}</p>

Expand Down
3 changes: 2 additions & 1 deletion lib/components/STableItem.vue
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
<script setup lang="ts">
defineProps<{
name: string
className?: string
width?: string
}>()
</script>

<template>
<div
class="STableItem"
:class="[`col-${name}`, { adjusted: width }]"
:class="[className, `col-${name}`, { adjusted: width }]"
>
<slot />
</div>
Expand Down

0 comments on commit a7bca60

Please sign in to comment.