@kikiloaw/simple-table 1.1.11 → 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 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`** | Rare. | Only use if your backend **strictly requires** `draw`, `start`, and `length` request parameters and fails with standard `page`/`per_page` params. |
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&draw=1&search[value]=john&order[0][column]=1&order[0][dir]=asc
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 | Example |
1160
- |-----------|-------------|---------|
1161
- | `start` | Record offset | `0`, `10`, `20` |
1162
- | `length` | Records per page | `10`, `25`, `50` |
1163
- | `draw` | Request counter | `1`, `2`, `3` |
1164
- | `search[value]` | Search query | `john`, `admin` |
1165
- | `order[0][column]` | Column index to sort | `0`, `1`, `2` |
1166
- | `order[0][dir]` | Sort direction | `asc`, `desc` |
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kikiloaw/simple-table",
3
- "version": "1.1.11",
3
+ "version": "1.1.17",
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",
@@ -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,
@@ -399,6 +399,7 @@ async function fetchData(params: any = {}) {
399
399
  }
400
400
 
401
401
  isLoading.value = true
402
+
402
403
  try {
403
404
  // Construct Query Parameters
404
405
  const url = new URL(props.fetchUrl, window.location.origin)
@@ -410,10 +411,29 @@ async function fetchData(params: any = {}) {
410
411
  url.searchParams.append('length', String(currentPerPage.value))
411
412
  url.searchParams.append('draw', String(drawCounter.value))
412
413
 
413
- if (searchQuery.value) {
414
- url.searchParams.append('search[value]', searchQuery.value)
415
- }
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')
416
435
 
436
+
417
437
  if (sortColumn.value) {
418
438
  // Find column index
419
439
  const columnIndex = props.columns.findIndex(col => {
@@ -470,7 +490,10 @@ async function fetchData(params: any = {}) {
470
490
 
471
491
  let data = await response.json()
472
492
 
473
- // Transform DataTables response to internal format
493
+ // Emit raw response immediately
494
+ emit('fetched', data)
495
+
496
+ // Transform DataTables response to internal format for internal use
474
497
  if (props.protocol === 'datatables') {
475
498
  // DataTables response: { draw, recordsTotal, recordsFiltered, data }
476
499
  // Transform to Laravel format internally
@@ -492,7 +515,7 @@ async function fetchData(params: any = {}) {
492
515
  }
493
516
 
494
517
  internalData.value = data
495
- emit('fetched', data)
518
+ // emit('fetched', data) // <-- Removed this, we emit raw data above
496
519
 
497
520
  // Store in cache if enabled
498
521
  if (props.enableCache) {
@@ -504,15 +527,55 @@ async function fetchData(params: any = {}) {
504
527
  isLoading.value = false
505
528
  }
506
529
  } else if (isServerSide.value) {
507
- router.visit(window.location.pathname, {
508
- data: {
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 = {
509
568
  page: params.page ?? currentPage.value,
510
569
  per_page: currentPerPage.value,
511
570
  search: params.search ?? searchQuery.value,
512
571
  sort: params.sort ?? sortColumn.value,
513
572
  order: params.order ?? sortDirection.value,
514
573
  ...(props.queryParams || {})
515
- },
574
+ }
575
+ }
576
+
577
+ router.visit(window.location.pathname, {
578
+ data,
516
579
  preserveState: true,
517
580
  preserveScroll: true,
518
581
  replace: true,
@@ -663,8 +726,9 @@ function handlePageChange(page: number) {
663
726
  emit('page-change', page)
664
727
  }
665
728
 
666
- function refresh() {
729
+ async function refresh() {
667
730
  currentPage.value = 1
731
+ await nextTick()
668
732
  fetchData()
669
733
  }
670
734