@kikiloaw/simple-table 1.0.3 → 1.0.4
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 +56 -11
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1055,28 +1055,73 @@ 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="columns" :data="data">
|
|
1072
1101
|
<template #cell-actions="{ row }">
|
|
1073
|
-
<
|
|
1074
|
-
|
|
1102
|
+
<div v-if="!row._isGroupHeader" class="flex gap-2">
|
|
1103
|
+
<Button variant="outline" size="sm" @click="edit(row)">Edit</Button>
|
|
1104
|
+
<Button variant="destructive" size="sm" @click="remove(row)">Delete</Button>
|
|
1105
|
+
</div>
|
|
1075
1106
|
</template>
|
|
1076
1107
|
</SimpleTable>
|
|
1077
1108
|
```
|
|
1078
1109
|
|
|
1079
|
-
|
|
1110
|
+
#### ⚠️ Important: Handling Group Headers
|
|
1111
|
+
|
|
1112
|
+
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`**.
|
|
1113
|
+
|
|
1114
|
+
```vue
|
|
1115
|
+
<template #cell-price="{ row }">
|
|
1116
|
+
<!-- ❌ Bad: Might crash on header row where row.price is undefined -->
|
|
1117
|
+
${{ row.price.toFixed(2) }}
|
|
1118
|
+
|
|
1119
|
+
<!-- ✅ Good: Safe check -->
|
|
1120
|
+
<span v-if="!row._isGroupHeader">
|
|
1121
|
+
${{ row.price?.toFixed(2) }}
|
|
1122
|
+
</span>
|
|
1123
|
+
</template>
|
|
1124
|
+
```
|
|
1080
1125
|
|
|
1081
1126
|
---
|
|
1082
1127
|
|