@kikiloaw/simple-table 1.1.4 → 1.1.8

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
@@ -30,14 +30,8 @@
30
30
  npm install @kikiloaw/simple-table
31
31
  ```
32
32
 
33
- ### Option 2: Local Copy
34
-
35
- ```bash
36
- cp -r path/to/SimpleTable /your-project/src/components/
37
- ```
38
33
 
39
34
  ---
40
-
41
35
  ## 🚀 Quick Start
42
36
 
43
37
  ### 1. Import the Component
@@ -422,10 +416,10 @@ SimpleTable supports three data modes:
422
416
 
423
417
  ### Protocol Formats
424
418
 
425
- | Protocol | When to Use | Backend Library |
426
- |----------|-------------|-----------------|
427
- | **`laravel`** (default) | New projects, standard Laravel apps | Native Laravel pagination |
428
- | **`datatables`** | Legacy projects, existing DataTables | Yajra DataTables |
419
+ | Protocol | When to Use | Backend Compatibility |
420
+ |----------|-------------|-----------------------|
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. |
429
423
 
430
424
  ---
431
425
 
@@ -464,6 +458,7 @@ SimpleTable supports three data modes:
464
458
  | `oddRowColor` | String | `'bg-white'` | Tailwind class for odd rows |
465
459
  | `evenRowColor` | String | `'bg-stone-100'` | Tailwind class for even rows |
466
460
  | `hoverColor` | String | `'hover:bg-stone-200'` | Tailwind class for row hover |
461
+ | `paginationColor` | String | `'#2563eb'` | Hex color for active pagination button |
467
462
 
468
463
  ---
469
464
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kikiloaw/simple-table",
3
- "version": "1.1.4",
3
+ "version": "1.1.8",
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",
@@ -12,7 +12,7 @@ import {
12
12
 
13
13
 
14
14
 
15
- import { useDebounceFn } from '@vueuse/core'
15
+ import { useDebounceFn, useWindowSize } from '@vueuse/core'
16
16
 
17
17
  /**
18
18
  * Props definition
@@ -49,6 +49,7 @@ interface Props {
49
49
  oddRowColor?: string // Tailwind color class, e.g. 'bg-white'
50
50
  evenRowColor?: string // Tailwind color class, e.g. 'bg-gray-50'
51
51
  hoverColor?: string // Tailwind color class for hover, e.g. 'hover:bg-gray-100'. If passed, we'll try to apply group-hover for fixed cols.
52
+ paginationColor?: string // Hex color for active pagination button (default: #2563eb)
52
53
  }
53
54
 
54
55
  const props = withDefaults(defineProps<Props>(), {
@@ -225,13 +226,24 @@ const serverMeta = computed(() => {
225
226
  const d = internalData.value as any
226
227
  // Handle standard Laravel Paginator or Resource Collection
227
228
  const meta = d.meta || d
229
+
230
+ // Polyfill missing 'from' and 'to' if server response (like DataTables custom backend) omits them
231
+ const page = meta.current_page ?? 1
232
+ const pPage = meta.per_page ?? currentPerPage.value
233
+ const total = meta.total ?? 0
234
+ const dataCount = Array.isArray(d.data) ? d.data.length : 0
235
+
236
+ // Calculate fallback values
237
+ const calculatedFrom = total === 0 ? 0 : ((page - 1) * pPage) + 1
238
+ const calculatedTo = total === 0 ? 0 : Math.min(calculatedFrom + dataCount - 1, total)
239
+
228
240
  return {
229
- current_page: meta.current_page ?? 1,
241
+ current_page: page,
230
242
  last_page: meta.last_page ?? 1,
231
- per_page: meta.per_page ?? currentPerPage.value,
232
- from: meta.from ?? 0,
233
- to: meta.to ?? 0,
234
- total: meta.total ?? 0,
243
+ per_page: pPage,
244
+ from: meta.from ?? calculatedFrom,
245
+ to: meta.to ?? calculatedTo,
246
+ total: total,
235
247
  links: meta.links ?? []
236
248
  }
237
249
  })
@@ -325,9 +337,16 @@ const paginationMeta = computed(() => {
325
337
 
326
338
  // -- Computed: Page Numbers for Pagination --
327
339
  const pageNumbers = computed(() => {
328
- const current = isServerSide.value ? (serverMeta.value?.current_page || 1) : currentPage.value
329
- const total = totalPages.value
330
- const delta = 2 // Number of pages to show on each side of current page
340
+ const { width } = useWindowSize()
341
+ const isMobile = width.value < 640
342
+ const isExtraSmall = width.value < 550
343
+
344
+ const current = Number(isServerSide.value ? (serverMeta.value?.current_page || 1) : currentPage.value)
345
+ const total = Number(totalPages.value)
346
+ // Show fewer surrounding pages on mobile to prevent overflow
347
+ // delta = 0 means only current page (plus first/last)
348
+ const delta = isExtraSmall ? 0 : (isMobile ? 1 : 2)
349
+
331
350
  const pages: (number | string)[] = []
332
351
 
333
352
  // Always show first page
@@ -948,16 +967,16 @@ function getCellStyle(col: any, index: number, totalCols: number) {
948
967
  </div>
949
968
 
950
969
  <!-- Pagination -->
951
- <div class="flex items-center justify-between px-2">
970
+ <div class="flex items-center justify-between flex-wrap gap-4 px-2 py-2">
952
971
  <div class="text-sm text-gray-500">
953
972
  Showing {{ paginationMeta.from }} to {{ paginationMeta.to }} of {{ paginationMeta.total }} results
954
973
  </div>
955
974
  <div class="flex items-center space-x-1">
956
975
  <!-- Previous Button -->
957
976
  <button
958
- class="inline-flex items-center justify-center rounded-md text-sm font-medium ring-offset-white transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-blue-500 focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 border border-gray-300 bg-white hover:bg-gray-100 hover:text-gray-900 h-9 px-3"
959
- :disabled="(isServerSide ? serverMeta?.current_page === 1 : currentPage === 1)"
960
- @click="handlePageChange(isServerSide ? (serverMeta?.current_page || 1) - 1 : currentPage - 1)"
977
+ class="inline-flex items-center justify-center rounded-md text-sm font-medium ring-offset-white transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-blue-500 focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 border border-gray-300 bg-white hover:bg-gray-100 hover:text-gray-900 h-9 px-2 sm:px-3"
978
+ :disabled="(isServerSide ? Number(serverMeta?.current_page) === 1 : currentPage === 1)"
979
+ @click="handlePageChange(isServerSide ? (Number(serverMeta?.current_page || 1)) - 1 : currentPage - 1)"
961
980
  >
962
981
  <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="h-4 w-4"><path d="m15 18-6-6 6-6"/></svg>
963
982
  <span class="ml-1 hidden sm:inline">Previous</span>
@@ -968,7 +987,7 @@ function getCellStyle(col: any, index: number, totalCols: number) {
968
987
  <!-- Ellipsis -->
969
988
  <span
970
989
  v-if="page === '...'"
971
- class="inline-flex items-center justify-center h-9 px-3 text-sm text-gray-500"
990
+ class="inline-flex items-center justify-center h-9 px-2 sm:px-3 text-sm text-gray-500"
972
991
  >
973
992
  ...
974
993
  </span>
@@ -976,12 +995,13 @@ function getCellStyle(col: any, index: number, totalCols: number) {
976
995
  <!-- Page Number Button -->
977
996
  <button
978
997
  v-else
979
- class="inline-flex items-center justify-center rounded-md text-sm font-medium ring-offset-white transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-blue-500 focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 border h-9 min-w-[36px] px-3"
998
+ class="inline-flex items-center justify-center rounded-md text-sm font-medium ring-offset-white transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-blue-500 focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 border h-9 min-w-[36px] px-2 sm:px-3"
980
999
  :class="[
981
- (isServerSide ? serverMeta?.current_page === page : currentPage === page)
982
- ? 'bg-blue-600 text-white border-blue-600 hover:bg-blue-700'
1000
+ (isServerSide ? Number(serverMeta?.current_page) === page : currentPage === page)
1001
+ ? 'hover:bg-blue-700'
983
1002
  : 'border-gray-300 bg-white hover:bg-gray-100 hover:text-gray-900'
984
1003
  ]"
1004
+ :style="(isServerSide ? Number(serverMeta?.current_page) === page : currentPage === page) ? `background-color: ${props.paginationColor || '#2563eb'} !important; color: white !important; border-color: ${props.paginationColor || '#2563eb'} !important;` : ''"
985
1005
  @click="handlePageChange(page as number)"
986
1006
  >
987
1007
  {{ page }}
@@ -990,9 +1010,9 @@ function getCellStyle(col: any, index: number, totalCols: number) {
990
1010
 
991
1011
  <!-- Next Button -->
992
1012
  <button
993
- class="inline-flex items-center justify-center rounded-md text-sm font-medium ring-offset-white transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-blue-500 focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 border border-gray-300 bg-white hover:bg-gray-100 hover:text-gray-900 h-9 px-3"
994
- :disabled="(isServerSide ? serverMeta?.current_page === serverMeta?.last_page : currentPage === totalPages)"
995
- @click="handlePageChange(isServerSide ? (serverMeta?.current_page || 1) + 1 : currentPage + 1)"
1013
+ class="inline-flex items-center justify-center rounded-md text-sm font-medium ring-offset-white transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-blue-500 focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 border border-gray-300 bg-white hover:bg-gray-100 hover:text-gray-900 h-9 px-2 sm:px-3"
1014
+ :disabled="(isServerSide ? Number(serverMeta?.current_page) === Number(serverMeta?.last_page) : currentPage === totalPages)"
1015
+ @click="handlePageChange(isServerSide ? (Number(serverMeta?.current_page || 1)) + 1 : currentPage + 1)"
996
1016
  >
997
1017
  <span class="mr-1 hidden sm:inline">Next</span>
998
1018
  <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="h-4 w-4"><path d="m9 18 6-6-6-6"/></svg>