@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.
Files changed (2) hide show
  1. package/README.md +56 -11
  2. 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 specific columns:**
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" fetch-url="/api/users">
1062
- <!-- Custom status badge -->
1063
- <template #cell-status="{ row }">
1065
+ <SimpleTable :columns="columns" :data="data">
1066
+ <!-- Status Badge with Conditional Color -->
1067
+ <template #cell-is_active="{ row }">
1064
1068
  <span
1065
- :class="row.status === 'active' ? 'badge-success' : 'badge-danger'"
1069
+ v-if="!row._isGroupHeader"
1070
+ :class="row.is_active ? 'text-green-600 font-bold' : 'text-red-600'"
1066
1071
  >
1067
- {{ row.status }}
1072
+ {{ row.is_active ? 'Active' : 'Inactive' }}
1068
1073
  </span>
1069
1074
  </template>
1070
-
1071
- <!-- Custom actions column -->
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
- <button @click="edit(row)" class="btn-sm">Edit</button>
1074
- <button @click="delete(row)" class="btn-sm btn-danger">Delete</button>
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
- **Slot Naming:** `#cell-{columnKey}`
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
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kikiloaw/simple-table",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "description": "A lightweight, dependency-light DataTable component for Vue 3 with Tailwind CSS",
5
5
  "main": "src/index.js",
6
6
  "module": "src/index.js",