@kikiloaw/simple-table 1.0.3 → 1.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -459,9 +459,9 @@ SimpleTable supports three data modes:
|
|
|
459
459
|
| Prop | Type | Default | Description |
|
|
460
460
|
|------|------|---------|-------------|
|
|
461
461
|
| `queryParams` | Object | `{}` | Additional parameters for every request |
|
|
462
|
-
| `oddRowColor` | String | `'bg-
|
|
463
|
-
| `evenRowColor` | String | `'bg-
|
|
464
|
-
| `hoverColor` | String | `'hover:bg-
|
|
462
|
+
| `oddRowColor` | String | `'bg-white'` | Tailwind class for odd rows |
|
|
463
|
+
| `evenRowColor` | String | `'bg-stone-100'` | Tailwind class for even rows |
|
|
464
|
+
| `hoverColor` | String | `'hover:bg-stone-200'` | Tailwind class for row hover |
|
|
465
465
|
|
|
466
466
|
---
|
|
467
467
|
|
|
@@ -1055,28 +1055,74 @@ const beforeRender = (rows) => {
|
|
|
1055
1055
|
|
|
1056
1056
|
### Custom Cell Rendering
|
|
1057
1057
|
|
|
1058
|
-
**Customize how data is displayed in
|
|
1058
|
+
**Customize how data is displayed in any column using named slots.**
|
|
1059
|
+
|
|
1060
|
+
**Slot Syntax:** `#cell-{columnKey}="{ row }"`
|
|
1061
|
+
|
|
1062
|
+
#### 1. Conditional Styling & Badges
|
|
1059
1063
|
|
|
1060
1064
|
```vue
|
|
1061
|
-
<SimpleTable :columns="columns"
|
|
1062
|
-
<!--
|
|
1063
|
-
<template #cell-
|
|
1065
|
+
<SimpleTable :columns="columns" :data="data">
|
|
1066
|
+
<!-- Status Badge with Conditional Color -->
|
|
1067
|
+
<template #cell-is_active="{ row }">
|
|
1064
1068
|
<span
|
|
1065
|
-
|
|
1069
|
+
v-if="!row._isGroupHeader"
|
|
1070
|
+
:class="row.is_active ? 'text-green-600 font-bold' : 'text-red-600'"
|
|
1066
1071
|
>
|
|
1067
|
-
{{ row.
|
|
1072
|
+
{{ row.is_active ? 'Active' : 'Inactive' }}
|
|
1068
1073
|
</span>
|
|
1069
1074
|
</template>
|
|
1070
|
-
|
|
1071
|
-
|
|
1075
|
+
</SimpleTable>
|
|
1076
|
+
```
|
|
1077
|
+
|
|
1078
|
+
#### 2. Rendering Lists/Tags
|
|
1079
|
+
|
|
1080
|
+
```vue
|
|
1081
|
+
<SimpleTable :columns="columns" :data="data">
|
|
1082
|
+
<!-- Loop through array data in a cell -->
|
|
1083
|
+
<template #cell-tags="{ row }">
|
|
1084
|
+
<div v-if="!row._isGroupHeader" class="flex gap-1 flex-wrap">
|
|
1085
|
+
<span
|
|
1086
|
+
v-for="tag in row.tags"
|
|
1087
|
+
:key="tag.id"
|
|
1088
|
+
class="bg-blue-100 text-blue-800 text-xs px-2 py-0.5 rounded"
|
|
1089
|
+
>
|
|
1090
|
+
{{ tag.name }}
|
|
1091
|
+
</span>
|
|
1092
|
+
</div>
|
|
1093
|
+
</template>
|
|
1094
|
+
</SimpleTable>
|
|
1095
|
+
```
|
|
1096
|
+
|
|
1097
|
+
#### 3. Action Buttons
|
|
1098
|
+
|
|
1099
|
+
```vue
|
|
1100
|
+
<SimpleTable :columns="
|
|
1101
|
+
" :data="data">
|
|
1072
1102
|
<template #cell-actions="{ row }">
|
|
1073
|
-
<
|
|
1074
|
-
|
|
1103
|
+
<div v-if="!row._isGroupHeader" class="flex gap-2">
|
|
1104
|
+
<Button variant="outline" size="sm" @click="edit(row)">Edit</Button>
|
|
1105
|
+
<Button variant="destructive" size="sm" @click="remove(row)">Delete</Button>
|
|
1106
|
+
</div>
|
|
1075
1107
|
</template>
|
|
1076
1108
|
</SimpleTable>
|
|
1077
1109
|
```
|
|
1078
1110
|
|
|
1079
|
-
|
|
1111
|
+
#### ⚠️ Important: Handling Group Headers
|
|
1112
|
+
|
|
1113
|
+
If you use **Group Headers**, your custom slots will technically be available for the header row too (though hidden by the colspan). To avoid errors accessing properties that don't exist on the header row, **always check `!row._isGroupHeader`**.
|
|
1114
|
+
|
|
1115
|
+
```vue
|
|
1116
|
+
<template #cell-price="{ row }">
|
|
1117
|
+
<!-- ❌ Bad: Might crash on header row where row.price is undefined -->
|
|
1118
|
+
${{ row.price.toFixed(2) }}
|
|
1119
|
+
|
|
1120
|
+
<!-- ✅ Good: Safe check -->
|
|
1121
|
+
<span v-if="!row._isGroupHeader">
|
|
1122
|
+
${{ row.price?.toFixed(2) }}
|
|
1123
|
+
</span>
|
|
1124
|
+
</template>
|
|
1125
|
+
```
|
|
1080
1126
|
|
|
1081
1127
|
---
|
|
1082
1128
|
|
package/package.json
CHANGED
package/src/SimpleTable.vue
CHANGED
|
@@ -62,9 +62,9 @@ const props = withDefaults(defineProps<Props>(), {
|
|
|
62
62
|
perPage: 10,
|
|
63
63
|
pageSizes: () => [10, 20, 30, 50, 100],
|
|
64
64
|
rowHeight: 38,
|
|
65
|
-
oddRowColor: 'bg-
|
|
66
|
-
evenRowColor: 'bg-
|
|
67
|
-
hoverColor: 'hover:bg-
|
|
65
|
+
oddRowColor: 'bg-white',
|
|
66
|
+
evenRowColor: 'bg-stone-100',
|
|
67
|
+
hoverColor: 'hover:bg-stone-200'
|
|
68
68
|
})
|
|
69
69
|
|
|
70
70
|
// ...
|
|
@@ -720,7 +720,7 @@ function getCellStyle(col: any) {
|
|
|
720
720
|
<select
|
|
721
721
|
:value="currentPerPage"
|
|
722
722
|
@change="(e: any) => handlePageSizeChange(e.target.value)"
|
|
723
|
-
class="h-10 w-[80px] appearance-none
|
|
723
|
+
class="h-10 w-[80px] appearance-none border border-input bg-background px-3 py-2 text-sm ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 cursor-pointer"
|
|
724
724
|
>
|
|
725
725
|
<option
|
|
726
726
|
v-for="pageSize in normalizedPageSizes"
|
|
@@ -741,7 +741,7 @@ function getCellStyle(col: any) {
|
|
|
741
741
|
v-model="searchQuery"
|
|
742
742
|
type="text"
|
|
743
743
|
placeholder="Search..."
|
|
744
|
-
class="flex h-10 w-full
|
|
744
|
+
class="flex h-10 w-full border border-input bg-background px-3 py-2 pl-8 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50"
|
|
745
745
|
/>
|
|
746
746
|
</div>
|
|
747
747
|
</div>
|
|
@@ -751,7 +751,7 @@ function getCellStyle(col: any) {
|
|
|
751
751
|
</div>
|
|
752
752
|
|
|
753
753
|
<!-- Table -->
|
|
754
|
-
<div class="
|
|
754
|
+
<div class="border bg-background overflow-x-auto relative">
|
|
755
755
|
<!-- We add min-w-full to Table to ensure it stretches -->
|
|
756
756
|
<Table class="min-w-full table-fixed">
|
|
757
757
|
<TableHeader>
|
|
@@ -21,7 +21,7 @@ const delegatedProps = computed(() => {
|
|
|
21
21
|
cn(
|
|
22
22
|
props.height || 'h-[38px]',
|
|
23
23
|
props.padding || 'px-2',
|
|
24
|
-
'text-left align-middle font-
|
|
24
|
+
'text-left align-middle font-bold text-muted-foreground [&:has([role=checkbox])]:pr-0',
|
|
25
25
|
props.class,
|
|
26
26
|
)
|
|
27
27
|
"
|
|
@@ -17,7 +17,7 @@ const delegatedProps = computed(() => {
|
|
|
17
17
|
<tr
|
|
18
18
|
:class="
|
|
19
19
|
cn(
|
|
20
|
-
'border-b transition-colors hover:bg-muted/50 data-[state=selected]:bg-muted',
|
|
20
|
+
'border-b border-stone-300 transition-colors hover:bg-muted/50 data-[state=selected]:bg-muted',
|
|
21
21
|
props.class,
|
|
22
22
|
)
|
|
23
23
|
"
|