@kikiloaw/simple-table 1.1.10 → 1.1.17
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 +15 -10
- package/package.json +1 -1
- package/src/SimpleTable.vue +77 -11
package/README.md
CHANGED
|
@@ -419,7 +419,7 @@ SimpleTable supports three data modes:
|
|
|
419
419
|
| Protocol | When to Use | Backend Compatibility |
|
|
420
420
|
|----------|-------------|-----------------------|
|
|
421
421
|
| **`laravel`** (default) | **Recommended for 99% of cases.** | Standard Laravel pagination, Resource Collections, and custom JSON responses (including simple DataTables-like backends). |
|
|
422
|
-
| **`datatables`** |
|
|
422
|
+
| **`datatables`** | Legacy integrations. | Sends full DataTables payload (`draw`, `columns[...]`, `order[...]`, `search[...]`). Use this if you are using `yajra/laravel-datatables` or a strict DataTables backend. |
|
|
423
423
|
|
|
424
424
|
---
|
|
425
425
|
|
|
@@ -1153,17 +1153,22 @@ $('#myTable').DataTable({
|
|
|
1153
1153
|
|
|
1154
1154
|
**SimpleTable sends:**
|
|
1155
1155
|
```
|
|
1156
|
-
GET /api/users?start=0&length=10&
|
|
1156
|
+
GET /api/users?draw=1&start=0&length=10&search[value]=john&search[regex]=false&order[0][column]=1&order[0][dir]=asc&columns[0][data]=id&columns[0][name]=id&columns[0][searchable]=true...
|
|
1157
1157
|
```
|
|
1158
1158
|
|
|
1159
|
-
| Parameter | Description |
|
|
1160
|
-
|
|
1161
|
-
| `
|
|
1162
|
-
| `
|
|
1163
|
-
| `
|
|
1164
|
-
| `search[value]` |
|
|
1165
|
-
| `
|
|
1166
|
-
| `order[0][
|
|
1159
|
+
| Parameter | Description |
|
|
1160
|
+
|-----------|-------------|
|
|
1161
|
+
| `draw` | Request counter |
|
|
1162
|
+
| `start` | Record offset (0, 10, 20...) |
|
|
1163
|
+
| `length` | Records per page (10, 25, 50...) |
|
|
1164
|
+
| `search[value]` | Global search term |
|
|
1165
|
+
| `search[regex]` | Regex flag (always false) |
|
|
1166
|
+
| `order[0][column]` | Index of column being sorted |
|
|
1167
|
+
| `order[0][dir]` | Sort direction (`asc`, `desc`) |
|
|
1168
|
+
| `columns[i][data]` | Column key |
|
|
1169
|
+
| `columns[i][name]` | Column name (or custom sort key) |
|
|
1170
|
+
| `columns[i][searchable]` | Searchable flag |
|
|
1171
|
+
| `columns[i][orderable]` | Sortable flag |
|
|
1167
1172
|
|
|
1168
1173
|
### Response Format
|
|
1169
1174
|
|
package/package.json
CHANGED
package/src/SimpleTable.vue
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<script setup lang="ts" generic="T">
|
|
2
|
-
import { computed, ref, watch, onMounted } from 'vue'
|
|
2
|
+
import { computed, ref, watch, onMounted, nextTick } from 'vue'
|
|
3
3
|
import { router } from '@inertiajs/vue3'
|
|
4
4
|
import {
|
|
5
5
|
Table,
|
|
@@ -341,8 +341,10 @@ const paginationMeta = computed(() => {
|
|
|
341
341
|
})
|
|
342
342
|
|
|
343
343
|
// -- Computed: Page Numbers for Pagination --
|
|
344
|
+
const { width } = useWindowSize()
|
|
345
|
+
|
|
344
346
|
const pageNumbers = computed(() => {
|
|
345
|
-
const { width } = useWindowSize()
|
|
347
|
+
// const { width } = useWindowSize() // MOVED OUTSIDE
|
|
346
348
|
const isMobile = width.value < 640
|
|
347
349
|
const isExtraSmall = width.value < 550
|
|
348
350
|
|
|
@@ -397,6 +399,7 @@ async function fetchData(params: any = {}) {
|
|
|
397
399
|
}
|
|
398
400
|
|
|
399
401
|
isLoading.value = true
|
|
402
|
+
|
|
400
403
|
try {
|
|
401
404
|
// Construct Query Parameters
|
|
402
405
|
const url = new URL(props.fetchUrl, window.location.origin)
|
|
@@ -408,10 +411,29 @@ async function fetchData(params: any = {}) {
|
|
|
408
411
|
url.searchParams.append('length', String(currentPerPage.value))
|
|
409
412
|
url.searchParams.append('draw', String(drawCounter.value))
|
|
410
413
|
|
|
411
|
-
if
|
|
412
|
-
|
|
413
|
-
|
|
414
|
+
// Defensive: Remove standard pagination params if they exist in the base URL
|
|
415
|
+
url.searchParams.delete('page')
|
|
416
|
+
url.searchParams.delete('per_page')
|
|
417
|
+
|
|
418
|
+
// Add Columns Configuration (Required for strict DataTables backends like Yajra)
|
|
419
|
+
props.columns.forEach((col, index) => {
|
|
420
|
+
const colName = typeof col.sortable === 'string' ? col.sortable : col.key
|
|
421
|
+
const isSortable = !!col.sortable
|
|
422
|
+
const isSearchable = true // Default to true as SimpleTable global search applies to all usually
|
|
423
|
+
|
|
424
|
+
url.searchParams.append(`columns[${index}][data]`, col.key)
|
|
425
|
+
url.searchParams.append(`columns[${index}][name]`, colName)
|
|
426
|
+
url.searchParams.append(`columns[${index}][searchable]`, String(isSearchable))
|
|
427
|
+
url.searchParams.append(`columns[${index}][orderable]`, String(isSortable))
|
|
428
|
+
url.searchParams.append(`columns[${index}][search][value]`, '')
|
|
429
|
+
url.searchParams.append(`columns[${index}][search][regex]`, 'false')
|
|
430
|
+
})
|
|
431
|
+
|
|
432
|
+
// Global Search (Always send, even if empty)
|
|
433
|
+
url.searchParams.append('search[value]', searchQuery.value || '')
|
|
434
|
+
url.searchParams.append('search[regex]', 'false')
|
|
414
435
|
|
|
436
|
+
|
|
415
437
|
if (sortColumn.value) {
|
|
416
438
|
// Find column index
|
|
417
439
|
const columnIndex = props.columns.findIndex(col => {
|
|
@@ -468,7 +490,10 @@ async function fetchData(params: any = {}) {
|
|
|
468
490
|
|
|
469
491
|
let data = await response.json()
|
|
470
492
|
|
|
471
|
-
//
|
|
493
|
+
// Emit raw response immediately
|
|
494
|
+
emit('fetched', data)
|
|
495
|
+
|
|
496
|
+
// Transform DataTables response to internal format for internal use
|
|
472
497
|
if (props.protocol === 'datatables') {
|
|
473
498
|
// DataTables response: { draw, recordsTotal, recordsFiltered, data }
|
|
474
499
|
// Transform to Laravel format internally
|
|
@@ -490,7 +515,7 @@ async function fetchData(params: any = {}) {
|
|
|
490
515
|
}
|
|
491
516
|
|
|
492
517
|
internalData.value = data
|
|
493
|
-
emit('fetched', data)
|
|
518
|
+
// emit('fetched', data) // <-- Removed this, we emit raw data above
|
|
494
519
|
|
|
495
520
|
// Store in cache if enabled
|
|
496
521
|
if (props.enableCache) {
|
|
@@ -502,15 +527,55 @@ async function fetchData(params: any = {}) {
|
|
|
502
527
|
isLoading.value = false
|
|
503
528
|
}
|
|
504
529
|
} else if (isServerSide.value) {
|
|
505
|
-
|
|
506
|
-
|
|
530
|
+
|
|
531
|
+
let data: any = {}
|
|
532
|
+
|
|
533
|
+
if (props.protocol === 'datatables') {
|
|
534
|
+
const start = params.page
|
|
535
|
+
? (params.page - 1) * currentPerPage.value
|
|
536
|
+
: (currentPage.value - 1) * currentPerPage.value
|
|
537
|
+
|
|
538
|
+
data = {
|
|
539
|
+
draw: drawCounter.value,
|
|
540
|
+
start: start,
|
|
541
|
+
length: currentPerPage.value,
|
|
542
|
+
'search[value]': params.search ?? searchQuery.value ?? '',
|
|
543
|
+
...props.queryParams
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
// Add Sort
|
|
547
|
+
if (params.sort || sortColumn.value) {
|
|
548
|
+
const colKey = params.sort ?? sortColumn.value
|
|
549
|
+
const colDir = params.order ?? sortDirection.value
|
|
550
|
+
|
|
551
|
+
// Find column index
|
|
552
|
+
const columnIndex = props.columns.findIndex(col => {
|
|
553
|
+
const sortKey = typeof col.sortable === 'string' ? col.sortable : col.key
|
|
554
|
+
return sortKey === colKey
|
|
555
|
+
})
|
|
556
|
+
|
|
557
|
+
if (columnIndex !== -1) {
|
|
558
|
+
data['order[0][column]'] = columnIndex
|
|
559
|
+
data['order[0][dir]'] = colDir
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
drawCounter.value++
|
|
564
|
+
|
|
565
|
+
} else {
|
|
566
|
+
// Laravel format (default)
|
|
567
|
+
data = {
|
|
507
568
|
page: params.page ?? currentPage.value,
|
|
508
569
|
per_page: currentPerPage.value,
|
|
509
570
|
search: params.search ?? searchQuery.value,
|
|
510
571
|
sort: params.sort ?? sortColumn.value,
|
|
511
572
|
order: params.order ?? sortDirection.value,
|
|
512
573
|
...(props.queryParams || {})
|
|
513
|
-
}
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
router.visit(window.location.pathname, {
|
|
578
|
+
data,
|
|
514
579
|
preserveState: true,
|
|
515
580
|
preserveScroll: true,
|
|
516
581
|
replace: true,
|
|
@@ -661,8 +726,9 @@ function handlePageChange(page: number) {
|
|
|
661
726
|
emit('page-change', page)
|
|
662
727
|
}
|
|
663
728
|
|
|
664
|
-
function refresh() {
|
|
729
|
+
async function refresh() {
|
|
665
730
|
currentPage.value = 1
|
|
731
|
+
await nextTick()
|
|
666
732
|
fetchData()
|
|
667
733
|
}
|
|
668
734
|
|