@kikiloaw/simple-table 1.0.0 → 1.0.1
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 +75 -17
- package/package.json +2 -2
- package/src/SimpleTable.vue +1 -8
package/README.md
CHANGED
|
@@ -263,19 +263,22 @@ const columns = [
|
|
|
263
263
|
|
|
264
264
|
**Use Case:** Add filters like status, department, date range, etc.
|
|
265
265
|
|
|
266
|
+
**Performance:** Query parameters are sent with every request but **do NOT auto-refetch**. This prevents unnecessary API calls when you have multiple filters. Call `refresh()` manually when ready.
|
|
267
|
+
|
|
266
268
|
```vue
|
|
267
269
|
<script setup>
|
|
268
270
|
import { ref } from 'vue'
|
|
269
271
|
|
|
272
|
+
const tableRef = ref()
|
|
270
273
|
const filters = ref({
|
|
271
274
|
status: 'active',
|
|
272
275
|
department_id: 5,
|
|
273
276
|
year: 2025
|
|
274
277
|
})
|
|
275
278
|
|
|
276
|
-
function
|
|
277
|
-
filters
|
|
278
|
-
|
|
279
|
+
function applyFilters() {
|
|
280
|
+
// After setting all filters, manually refresh
|
|
281
|
+
tableRef.value?.refresh()
|
|
279
282
|
}
|
|
280
283
|
</script>
|
|
281
284
|
|
|
@@ -291,10 +294,13 @@ function updateStatus(newStatus) {
|
|
|
291
294
|
<option :value="1">IT</option>
|
|
292
295
|
<option :value="5">HR</option>
|
|
293
296
|
</select>
|
|
297
|
+
|
|
298
|
+
<button @click="applyFilters" class="btn">Apply Filters</button>
|
|
294
299
|
</div>
|
|
295
300
|
|
|
296
301
|
<!-- Table with filters -->
|
|
297
302
|
<SimpleTable
|
|
303
|
+
ref="tableRef"
|
|
298
304
|
fetch-url="/api/users"
|
|
299
305
|
:columns="columns"
|
|
300
306
|
:query-params="filters"
|
|
@@ -302,6 +308,8 @@ function updateStatus(newStatus) {
|
|
|
302
308
|
</template>
|
|
303
309
|
```
|
|
304
310
|
|
|
311
|
+
**Important:** Query parameters are **NOT automatically watched**. This prevents multiple API calls when you have many filters. Call `tableRef.value?.refresh()` manually when you want to refetch.
|
|
312
|
+
|
|
305
313
|
**API Request:**
|
|
306
314
|
```
|
|
307
315
|
GET /api/users?page=1&per_page=10&status=active&department_id=5&year=2025
|
|
@@ -379,24 +387,74 @@ function handleCreate() {
|
|
|
379
387
|
|
|
380
388
|
### Custom Actions and Slots
|
|
381
389
|
|
|
382
|
-
**Add custom buttons to the toolbar:**
|
|
390
|
+
**Add custom buttons to the toolbar with access to table data:**
|
|
383
391
|
|
|
384
392
|
```vue
|
|
385
|
-
<
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
393
|
+
<script setup>
|
|
394
|
+
import { Download, Printer, Trash } from 'lucide-vue-next'
|
|
395
|
+
|
|
396
|
+
const handleExport = (type, rows) => {
|
|
397
|
+
console.log(`Exporting ${rows.length} rows as ${type}`)
|
|
398
|
+
|
|
399
|
+
if (type === 'csv') {
|
|
400
|
+
const csv = rows.map(row =>
|
|
401
|
+
`${row.id},${row.name},${row.email}`
|
|
402
|
+
).join('\n')
|
|
403
|
+
|
|
404
|
+
downloadCSV(csv, 'export.csv')
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
const handleBulkDelete = (rows) => {
|
|
409
|
+
const ids = rows.map(r => r.id)
|
|
410
|
+
if (confirm(`Delete ${ids.length} items?`)) {
|
|
411
|
+
axios.delete('/api/bulk-delete', { data: { ids } })
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
const downloadCSV = (content, filename) => {
|
|
416
|
+
const blob = new Blob([content], { type: 'text/csv' })
|
|
417
|
+
const url = URL.createObjectURL(blob)
|
|
418
|
+
const a = document.createElement('a')
|
|
419
|
+
a.href = url
|
|
420
|
+
a.download = filename
|
|
421
|
+
a.click()
|
|
422
|
+
}
|
|
423
|
+
</script>
|
|
424
|
+
|
|
425
|
+
<template>
|
|
426
|
+
<SimpleTable :columns="columns" fetch-url="/api/users">
|
|
427
|
+
<template #actions="{ rows, columns }">
|
|
428
|
+
<Button @click="handleExport('csv', rows)">
|
|
429
|
+
<Download class="mr-2 h-4 w-4" />
|
|
430
|
+
Export ({{ rows.length }})
|
|
431
|
+
</Button>
|
|
432
|
+
|
|
433
|
+
<Button @click="handleExport('excel', rows)">
|
|
434
|
+
<Download class="mr-2 h-4 w-4" />
|
|
435
|
+
Excel
|
|
436
|
+
</Button>
|
|
437
|
+
|
|
438
|
+
<Button @click="handleBulkDelete(rows)" variant="destructive">
|
|
439
|
+
<Trash class="mr-2 h-4 w-4" />
|
|
440
|
+
Bulk Delete
|
|
441
|
+
</Button>
|
|
442
|
+
</template>
|
|
443
|
+
</SimpleTable>
|
|
444
|
+
</template>
|
|
395
445
|
```
|
|
396
446
|
|
|
397
|
-
**
|
|
398
|
-
-
|
|
399
|
-
-
|
|
447
|
+
**Slot Props:**
|
|
448
|
+
- **`rows`**: Currently visible table data (array of objects)
|
|
449
|
+
- **`columns`**: Column definitions (array of column config)
|
|
450
|
+
|
|
451
|
+
**Use Cases:**
|
|
452
|
+
- ✅ Custom export buttons (CSV, Excel, PDF)
|
|
453
|
+
- ✅ Bulk actions (delete, update, approve)
|
|
454
|
+
- ✅ Print functionality
|
|
455
|
+
- ✅ Custom filters or search
|
|
456
|
+
- ✅ Integration with third-party libraries
|
|
457
|
+
|
|
400
458
|
|
|
401
459
|
---
|
|
402
460
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kikiloaw/simple-table",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
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",
|
|
@@ -29,4 +29,4 @@
|
|
|
29
29
|
"type": "git",
|
|
30
30
|
"url": "git+https://github.com/kikiloaw/simple-table.git"
|
|
31
31
|
}
|
|
32
|
-
}
|
|
32
|
+
}
|
package/src/SimpleTable.vue
CHANGED
|
@@ -48,6 +48,7 @@ interface Props {
|
|
|
48
48
|
|
|
49
49
|
const props = withDefaults(defineProps<Props>(), {
|
|
50
50
|
data: () => [],
|
|
51
|
+
columns: () => [],
|
|
51
52
|
mode: 'auto',
|
|
52
53
|
protocol: 'laravel',
|
|
53
54
|
searchable: true,
|
|
@@ -164,14 +165,6 @@ watch(() => props.data, (newVal) => {
|
|
|
164
165
|
internalData.value = newVal
|
|
165
166
|
}, { deep: true })
|
|
166
167
|
|
|
167
|
-
// Watch queryParams and refetch when they change
|
|
168
|
-
watch(() => props.queryParams, () => {
|
|
169
|
-
if (isServerSide.value) {
|
|
170
|
-
currentPage.value = 1 // Reset to first page when filters change
|
|
171
|
-
fetchData()
|
|
172
|
-
}
|
|
173
|
-
}, { deep: true })
|
|
174
|
-
|
|
175
168
|
// -- Computed: Mode Detection --
|
|
176
169
|
const isServerSide = computed(() => {
|
|
177
170
|
if (props.mode === 'server') return true
|