@toniel/laravel-tanstack-pagination 0.1.1 → 0.1.2
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 +155 -1
- package/dist/index.d.mts +12 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +12 -3
- package/dist/index.mjs +12 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -94,13 +94,15 @@ Main composable for handling Laravel pagination.
|
|
|
94
94
|
| `search` | `Ref<string>` | Current search query |
|
|
95
95
|
| `sortBy` | `Ref<string \| null>` | Current sort column |
|
|
96
96
|
| `sortDirection` | `Ref<'asc' \| 'desc'>` | Sort direction |
|
|
97
|
-
| `filters` | `ComputedRef<PaginationFilters>` | All active filters |
|
|
97
|
+
| `filters` | `ComputedRef<PaginationFilters>` | All active filters (including custom filters) |
|
|
98
|
+
| `customFilters` | `Ref<Record<string, any>>` | Custom filter state (for external use) |
|
|
98
99
|
| `isLoading` | `Ref<boolean>` | Loading state from TanStack Query |
|
|
99
100
|
| `error` | `Ref<Error \| null>` | Error state from TanStack Query |
|
|
100
101
|
| `handlePageChange` | `(page: number) => void` | Change page handler |
|
|
101
102
|
| `handlePerPageChange` | `(perPage: number) => void` | Change per page handler |
|
|
102
103
|
| `handleSearchChange` | `(search: string) => void` | Search change handler (debounced) |
|
|
103
104
|
| `handleSortChange` | `(column: string) => void` | Toggle sort on column |
|
|
105
|
+
| `handleFilterChange` | `(filters: Record<string, any>) => void` | Bulk update custom filters |
|
|
104
106
|
| `setFilter` | `(key: string, value: any) => void` | Add custom filter |
|
|
105
107
|
| `removeFilter` | `(key: string) => void` | Remove custom filter |
|
|
106
108
|
| `resetFilters` | `() => void` | Reset all filters to defaults |
|
|
@@ -257,6 +259,158 @@ npm install @toniel/laravel-tanstack-datatable
|
|
|
257
259
|
|
|
258
260
|
See: https://www.npmjs.com/package/@toniel/laravel-tanstack-datatable
|
|
259
261
|
|
|
262
|
+
## 🔍 Filtering
|
|
263
|
+
|
|
264
|
+
The `usePagination` composable provides comprehensive filter management with proper state persistence across page changes.
|
|
265
|
+
|
|
266
|
+
### Single Filter Operations
|
|
267
|
+
|
|
268
|
+
```typescript
|
|
269
|
+
const {
|
|
270
|
+
setFilter,
|
|
271
|
+
removeFilter,
|
|
272
|
+
customFilters,
|
|
273
|
+
refetch,
|
|
274
|
+
} = usePagination(fetchFn, { queryKey: 'users' })
|
|
275
|
+
|
|
276
|
+
// Set a single filter
|
|
277
|
+
setFilter('status', 'active')
|
|
278
|
+
setFilter('category', 'A')
|
|
279
|
+
|
|
280
|
+
// Remove a filter
|
|
281
|
+
removeFilter('status')
|
|
282
|
+
|
|
283
|
+
// The query will automatically refetch when filters change
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
### Bulk Filter Operations
|
|
287
|
+
|
|
288
|
+
```typescript
|
|
289
|
+
const {
|
|
290
|
+
handleFilterChange,
|
|
291
|
+
customFilters,
|
|
292
|
+
refetch,
|
|
293
|
+
} = usePagination(fetchFn, { queryKey: 'users' })
|
|
294
|
+
|
|
295
|
+
// Bulk update multiple filters at once
|
|
296
|
+
handleFilterChange({
|
|
297
|
+
status: 'active',
|
|
298
|
+
category: 'A',
|
|
299
|
+
year: '2024'
|
|
300
|
+
})
|
|
301
|
+
|
|
302
|
+
// Or pass partial updates (will merge with existing)
|
|
303
|
+
handleFilterChange({
|
|
304
|
+
...customFilters.value,
|
|
305
|
+
status: 'inactive'
|
|
306
|
+
})
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+
### Filter State Persistence
|
|
310
|
+
|
|
311
|
+
Custom filters are properly included in the TanStack Query cache key, ensuring:
|
|
312
|
+
- Filters persist when changing pages
|
|
313
|
+
- Filters persist when changing per page
|
|
314
|
+
- Correct cache invalidation on filter changes
|
|
315
|
+
- Back/forward navigation works correctly
|
|
316
|
+
|
|
317
|
+
```typescript
|
|
318
|
+
// Filters are automatically included in queryKey
|
|
319
|
+
const { filters } = usePagination(fetchFn, { queryKey: 'users' })
|
|
320
|
+
|
|
321
|
+
// filters.value = { page: 1, per_page: 10, search: '', status: 'active', category: 'A' }
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
### Reset Filters
|
|
325
|
+
|
|
326
|
+
```typescript
|
|
327
|
+
const {
|
|
328
|
+
resetFilters,
|
|
329
|
+
customFilters,
|
|
330
|
+
search,
|
|
331
|
+
perPage,
|
|
332
|
+
} = usePagination(fetchFn, { queryKey: 'users', defaultPerPage: 20 })
|
|
333
|
+
|
|
334
|
+
// Reset all filters to defaults
|
|
335
|
+
resetFilters()
|
|
336
|
+
|
|
337
|
+
// After reset:
|
|
338
|
+
// - customFilters = {}
|
|
339
|
+
// - search = ''
|
|
340
|
+
// - perPage = 20
|
|
341
|
+
// - page = 1
|
|
342
|
+
```
|
|
343
|
+
|
|
344
|
+
### Example: Complex Filter Form
|
|
345
|
+
|
|
346
|
+
```typescript
|
|
347
|
+
<script setup lang="ts">
|
|
348
|
+
import { ref, computed } from 'vue'
|
|
349
|
+
import { usePagination } from '@toniel/laravel-tanstack-pagination'
|
|
350
|
+
|
|
351
|
+
// Filter form state (separate from composable)
|
|
352
|
+
const filterForm = ref({
|
|
353
|
+
status: '',
|
|
354
|
+
category: '',
|
|
355
|
+
year: new Date().getFullYear().toString(),
|
|
356
|
+
month: '',
|
|
357
|
+
})
|
|
358
|
+
|
|
359
|
+
const {
|
|
360
|
+
tableData,
|
|
361
|
+
pagination,
|
|
362
|
+
customFilters,
|
|
363
|
+
setFilter,
|
|
364
|
+
removeFilter,
|
|
365
|
+
handlePageChange,
|
|
366
|
+
refetch,
|
|
367
|
+
} = usePagination(
|
|
368
|
+
(filters) => axios.get('/api/transactions', { params: filters }),
|
|
369
|
+
{ queryKey: 'transactions', defaultPerPage: 20 }
|
|
370
|
+
)
|
|
371
|
+
|
|
372
|
+
// Apply filters
|
|
373
|
+
const applyFilters = () => {
|
|
374
|
+
// Clear existing custom filters first
|
|
375
|
+
if (filterForm.value.status) {
|
|
376
|
+
setFilter('status', filterForm.value.status)
|
|
377
|
+
} else {
|
|
378
|
+
removeFilter('status')
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
if (filterForm.value.category) {
|
|
382
|
+
setFilter('category', filterForm.value.category)
|
|
383
|
+
} else {
|
|
384
|
+
removeFilter('category')
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
if (filterForm.value.year) {
|
|
388
|
+
setFilter('year', filterForm.value.year)
|
|
389
|
+
} else {
|
|
390
|
+
removeFilter('year')
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
if (filterForm.value.month) {
|
|
394
|
+
setFilter('month', filterForm.value.month)
|
|
395
|
+
} else {
|
|
396
|
+
removeFilter('month')
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
refetch()
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
// Clear all filters
|
|
403
|
+
const clearFilters = () => {
|
|
404
|
+
filterForm.value = { status: '', category: '', year: new Date().getFullYear().toString(), month: '' }
|
|
405
|
+
removeFilter('status')
|
|
406
|
+
removeFilter('category')
|
|
407
|
+
removeFilter('year')
|
|
408
|
+
removeFilter('month')
|
|
409
|
+
refetch()
|
|
410
|
+
}
|
|
411
|
+
</script>
|
|
412
|
+
```
|
|
413
|
+
|
|
260
414
|
## 🔧 Laravel Backend Setup
|
|
261
415
|
|
|
262
416
|
Your Laravel API should return paginated responses in this format:
|
package/dist/index.d.mts
CHANGED
|
@@ -52,6 +52,7 @@ declare function usePagination<T = any>(fetchFn: (filters: PaginationFilters) =>
|
|
|
52
52
|
handlePerPageChange: (newPerPage: number) => void;
|
|
53
53
|
handleSearchChange: (newSearch: string) => void;
|
|
54
54
|
handleSortChange: (column: string) => void;
|
|
55
|
+
handleFilterChange: (newFilters: Record<string, any>) => void;
|
|
55
56
|
resetFilters: () => void;
|
|
56
57
|
setFilter: (key: string, value: any) => void;
|
|
57
58
|
removeFilter: (key: string) => void;
|
|
@@ -101,6 +102,7 @@ declare function usePagination<T = any>(fetchFn: (filters: PaginationFilters) =>
|
|
|
101
102
|
sortBy: vue.Ref<string | null, string | null>;
|
|
102
103
|
sortDirection: vue.Ref<"asc" | "desc", "asc" | "desc">;
|
|
103
104
|
filters: vue.ComputedRef<PaginationFilters>;
|
|
105
|
+
customFilters: vue.Ref<Record<string, any>, Record<string, any>>;
|
|
104
106
|
} | {
|
|
105
107
|
tableData: vue.ComputedRef<T[]>;
|
|
106
108
|
pagination: vue.ComputedRef<LaravelPaginationResponse<T> | null>;
|
|
@@ -108,6 +110,7 @@ declare function usePagination<T = any>(fetchFn: (filters: PaginationFilters) =>
|
|
|
108
110
|
handlePerPageChange: (newPerPage: number) => void;
|
|
109
111
|
handleSearchChange: (newSearch: string) => void;
|
|
110
112
|
handleSortChange: (column: string) => void;
|
|
113
|
+
handleFilterChange: (newFilters: Record<string, any>) => void;
|
|
111
114
|
resetFilters: () => void;
|
|
112
115
|
setFilter: (key: string, value: any) => void;
|
|
113
116
|
removeFilter: (key: string) => void;
|
|
@@ -157,6 +160,7 @@ declare function usePagination<T = any>(fetchFn: (filters: PaginationFilters) =>
|
|
|
157
160
|
sortBy: vue.Ref<string | null, string | null>;
|
|
158
161
|
sortDirection: vue.Ref<"asc" | "desc", "asc" | "desc">;
|
|
159
162
|
filters: vue.ComputedRef<PaginationFilters>;
|
|
163
|
+
customFilters: vue.Ref<Record<string, any>, Record<string, any>>;
|
|
160
164
|
} | {
|
|
161
165
|
tableData: vue.ComputedRef<T[]>;
|
|
162
166
|
pagination: vue.ComputedRef<LaravelPaginationResponse<T> | null>;
|
|
@@ -164,6 +168,7 @@ declare function usePagination<T = any>(fetchFn: (filters: PaginationFilters) =>
|
|
|
164
168
|
handlePerPageChange: (newPerPage: number) => void;
|
|
165
169
|
handleSearchChange: (newSearch: string) => void;
|
|
166
170
|
handleSortChange: (column: string) => void;
|
|
171
|
+
handleFilterChange: (newFilters: Record<string, any>) => void;
|
|
167
172
|
resetFilters: () => void;
|
|
168
173
|
setFilter: (key: string, value: any) => void;
|
|
169
174
|
removeFilter: (key: string) => void;
|
|
@@ -213,6 +218,7 @@ declare function usePagination<T = any>(fetchFn: (filters: PaginationFilters) =>
|
|
|
213
218
|
sortBy: vue.Ref<string | null, string | null>;
|
|
214
219
|
sortDirection: vue.Ref<"asc" | "desc", "asc" | "desc">;
|
|
215
220
|
filters: vue.ComputedRef<PaginationFilters>;
|
|
221
|
+
customFilters: vue.Ref<Record<string, any>, Record<string, any>>;
|
|
216
222
|
} | {
|
|
217
223
|
tableData: vue.ComputedRef<T[]>;
|
|
218
224
|
pagination: vue.ComputedRef<LaravelPaginationResponse<T> | null>;
|
|
@@ -220,6 +226,7 @@ declare function usePagination<T = any>(fetchFn: (filters: PaginationFilters) =>
|
|
|
220
226
|
handlePerPageChange: (newPerPage: number) => void;
|
|
221
227
|
handleSearchChange: (newSearch: string) => void;
|
|
222
228
|
handleSortChange: (column: string) => void;
|
|
229
|
+
handleFilterChange: (newFilters: Record<string, any>) => void;
|
|
223
230
|
resetFilters: () => void;
|
|
224
231
|
setFilter: (key: string, value: any) => void;
|
|
225
232
|
removeFilter: (key: string) => void;
|
|
@@ -269,6 +276,7 @@ declare function usePagination<T = any>(fetchFn: (filters: PaginationFilters) =>
|
|
|
269
276
|
sortBy: vue.Ref<string | null, string | null>;
|
|
270
277
|
sortDirection: vue.Ref<"asc" | "desc", "asc" | "desc">;
|
|
271
278
|
filters: vue.ComputedRef<PaginationFilters>;
|
|
279
|
+
customFilters: vue.Ref<Record<string, any>, Record<string, any>>;
|
|
272
280
|
} | {
|
|
273
281
|
tableData: vue.ComputedRef<T[]>;
|
|
274
282
|
pagination: vue.ComputedRef<LaravelPaginationResponse<T> | null>;
|
|
@@ -276,6 +284,7 @@ declare function usePagination<T = any>(fetchFn: (filters: PaginationFilters) =>
|
|
|
276
284
|
handlePerPageChange: (newPerPage: number) => void;
|
|
277
285
|
handleSearchChange: (newSearch: string) => void;
|
|
278
286
|
handleSortChange: (column: string) => void;
|
|
287
|
+
handleFilterChange: (newFilters: Record<string, any>) => void;
|
|
279
288
|
resetFilters: () => void;
|
|
280
289
|
setFilter: (key: string, value: any) => void;
|
|
281
290
|
removeFilter: (key: string) => void;
|
|
@@ -325,6 +334,7 @@ declare function usePagination<T = any>(fetchFn: (filters: PaginationFilters) =>
|
|
|
325
334
|
sortBy: vue.Ref<string | null, string | null>;
|
|
326
335
|
sortDirection: vue.Ref<"asc" | "desc", "asc" | "desc">;
|
|
327
336
|
filters: vue.ComputedRef<PaginationFilters>;
|
|
337
|
+
customFilters: vue.Ref<Record<string, any>, Record<string, any>>;
|
|
328
338
|
} | {
|
|
329
339
|
tableData: vue.ComputedRef<T[]>;
|
|
330
340
|
pagination: vue.ComputedRef<LaravelPaginationResponse<T> | null>;
|
|
@@ -332,6 +342,7 @@ declare function usePagination<T = any>(fetchFn: (filters: PaginationFilters) =>
|
|
|
332
342
|
handlePerPageChange: (newPerPage: number) => void;
|
|
333
343
|
handleSearchChange: (newSearch: string) => void;
|
|
334
344
|
handleSortChange: (column: string) => void;
|
|
345
|
+
handleFilterChange: (newFilters: Record<string, any>) => void;
|
|
335
346
|
resetFilters: () => void;
|
|
336
347
|
setFilter: (key: string, value: any) => void;
|
|
337
348
|
removeFilter: (key: string) => void;
|
|
@@ -381,6 +392,7 @@ declare function usePagination<T = any>(fetchFn: (filters: PaginationFilters) =>
|
|
|
381
392
|
sortBy: vue.Ref<string | null, string | null>;
|
|
382
393
|
sortDirection: vue.Ref<"asc" | "desc", "asc" | "desc">;
|
|
383
394
|
filters: vue.ComputedRef<PaginationFilters>;
|
|
395
|
+
customFilters: vue.Ref<Record<string, any>, Record<string, any>>;
|
|
384
396
|
};
|
|
385
397
|
|
|
386
398
|
interface NumberingOptions {
|
package/dist/index.d.ts
CHANGED
|
@@ -52,6 +52,7 @@ declare function usePagination<T = any>(fetchFn: (filters: PaginationFilters) =>
|
|
|
52
52
|
handlePerPageChange: (newPerPage: number) => void;
|
|
53
53
|
handleSearchChange: (newSearch: string) => void;
|
|
54
54
|
handleSortChange: (column: string) => void;
|
|
55
|
+
handleFilterChange: (newFilters: Record<string, any>) => void;
|
|
55
56
|
resetFilters: () => void;
|
|
56
57
|
setFilter: (key: string, value: any) => void;
|
|
57
58
|
removeFilter: (key: string) => void;
|
|
@@ -101,6 +102,7 @@ declare function usePagination<T = any>(fetchFn: (filters: PaginationFilters) =>
|
|
|
101
102
|
sortBy: vue.Ref<string | null, string | null>;
|
|
102
103
|
sortDirection: vue.Ref<"asc" | "desc", "asc" | "desc">;
|
|
103
104
|
filters: vue.ComputedRef<PaginationFilters>;
|
|
105
|
+
customFilters: vue.Ref<Record<string, any>, Record<string, any>>;
|
|
104
106
|
} | {
|
|
105
107
|
tableData: vue.ComputedRef<T[]>;
|
|
106
108
|
pagination: vue.ComputedRef<LaravelPaginationResponse<T> | null>;
|
|
@@ -108,6 +110,7 @@ declare function usePagination<T = any>(fetchFn: (filters: PaginationFilters) =>
|
|
|
108
110
|
handlePerPageChange: (newPerPage: number) => void;
|
|
109
111
|
handleSearchChange: (newSearch: string) => void;
|
|
110
112
|
handleSortChange: (column: string) => void;
|
|
113
|
+
handleFilterChange: (newFilters: Record<string, any>) => void;
|
|
111
114
|
resetFilters: () => void;
|
|
112
115
|
setFilter: (key: string, value: any) => void;
|
|
113
116
|
removeFilter: (key: string) => void;
|
|
@@ -157,6 +160,7 @@ declare function usePagination<T = any>(fetchFn: (filters: PaginationFilters) =>
|
|
|
157
160
|
sortBy: vue.Ref<string | null, string | null>;
|
|
158
161
|
sortDirection: vue.Ref<"asc" | "desc", "asc" | "desc">;
|
|
159
162
|
filters: vue.ComputedRef<PaginationFilters>;
|
|
163
|
+
customFilters: vue.Ref<Record<string, any>, Record<string, any>>;
|
|
160
164
|
} | {
|
|
161
165
|
tableData: vue.ComputedRef<T[]>;
|
|
162
166
|
pagination: vue.ComputedRef<LaravelPaginationResponse<T> | null>;
|
|
@@ -164,6 +168,7 @@ declare function usePagination<T = any>(fetchFn: (filters: PaginationFilters) =>
|
|
|
164
168
|
handlePerPageChange: (newPerPage: number) => void;
|
|
165
169
|
handleSearchChange: (newSearch: string) => void;
|
|
166
170
|
handleSortChange: (column: string) => void;
|
|
171
|
+
handleFilterChange: (newFilters: Record<string, any>) => void;
|
|
167
172
|
resetFilters: () => void;
|
|
168
173
|
setFilter: (key: string, value: any) => void;
|
|
169
174
|
removeFilter: (key: string) => void;
|
|
@@ -213,6 +218,7 @@ declare function usePagination<T = any>(fetchFn: (filters: PaginationFilters) =>
|
|
|
213
218
|
sortBy: vue.Ref<string | null, string | null>;
|
|
214
219
|
sortDirection: vue.Ref<"asc" | "desc", "asc" | "desc">;
|
|
215
220
|
filters: vue.ComputedRef<PaginationFilters>;
|
|
221
|
+
customFilters: vue.Ref<Record<string, any>, Record<string, any>>;
|
|
216
222
|
} | {
|
|
217
223
|
tableData: vue.ComputedRef<T[]>;
|
|
218
224
|
pagination: vue.ComputedRef<LaravelPaginationResponse<T> | null>;
|
|
@@ -220,6 +226,7 @@ declare function usePagination<T = any>(fetchFn: (filters: PaginationFilters) =>
|
|
|
220
226
|
handlePerPageChange: (newPerPage: number) => void;
|
|
221
227
|
handleSearchChange: (newSearch: string) => void;
|
|
222
228
|
handleSortChange: (column: string) => void;
|
|
229
|
+
handleFilterChange: (newFilters: Record<string, any>) => void;
|
|
223
230
|
resetFilters: () => void;
|
|
224
231
|
setFilter: (key: string, value: any) => void;
|
|
225
232
|
removeFilter: (key: string) => void;
|
|
@@ -269,6 +276,7 @@ declare function usePagination<T = any>(fetchFn: (filters: PaginationFilters) =>
|
|
|
269
276
|
sortBy: vue.Ref<string | null, string | null>;
|
|
270
277
|
sortDirection: vue.Ref<"asc" | "desc", "asc" | "desc">;
|
|
271
278
|
filters: vue.ComputedRef<PaginationFilters>;
|
|
279
|
+
customFilters: vue.Ref<Record<string, any>, Record<string, any>>;
|
|
272
280
|
} | {
|
|
273
281
|
tableData: vue.ComputedRef<T[]>;
|
|
274
282
|
pagination: vue.ComputedRef<LaravelPaginationResponse<T> | null>;
|
|
@@ -276,6 +284,7 @@ declare function usePagination<T = any>(fetchFn: (filters: PaginationFilters) =>
|
|
|
276
284
|
handlePerPageChange: (newPerPage: number) => void;
|
|
277
285
|
handleSearchChange: (newSearch: string) => void;
|
|
278
286
|
handleSortChange: (column: string) => void;
|
|
287
|
+
handleFilterChange: (newFilters: Record<string, any>) => void;
|
|
279
288
|
resetFilters: () => void;
|
|
280
289
|
setFilter: (key: string, value: any) => void;
|
|
281
290
|
removeFilter: (key: string) => void;
|
|
@@ -325,6 +334,7 @@ declare function usePagination<T = any>(fetchFn: (filters: PaginationFilters) =>
|
|
|
325
334
|
sortBy: vue.Ref<string | null, string | null>;
|
|
326
335
|
sortDirection: vue.Ref<"asc" | "desc", "asc" | "desc">;
|
|
327
336
|
filters: vue.ComputedRef<PaginationFilters>;
|
|
337
|
+
customFilters: vue.Ref<Record<string, any>, Record<string, any>>;
|
|
328
338
|
} | {
|
|
329
339
|
tableData: vue.ComputedRef<T[]>;
|
|
330
340
|
pagination: vue.ComputedRef<LaravelPaginationResponse<T> | null>;
|
|
@@ -332,6 +342,7 @@ declare function usePagination<T = any>(fetchFn: (filters: PaginationFilters) =>
|
|
|
332
342
|
handlePerPageChange: (newPerPage: number) => void;
|
|
333
343
|
handleSearchChange: (newSearch: string) => void;
|
|
334
344
|
handleSortChange: (column: string) => void;
|
|
345
|
+
handleFilterChange: (newFilters: Record<string, any>) => void;
|
|
335
346
|
resetFilters: () => void;
|
|
336
347
|
setFilter: (key: string, value: any) => void;
|
|
337
348
|
removeFilter: (key: string) => void;
|
|
@@ -381,6 +392,7 @@ declare function usePagination<T = any>(fetchFn: (filters: PaginationFilters) =>
|
|
|
381
392
|
sortBy: vue.Ref<string | null, string | null>;
|
|
382
393
|
sortDirection: vue.Ref<"asc" | "desc", "asc" | "desc">;
|
|
383
394
|
filters: vue.ComputedRef<PaginationFilters>;
|
|
395
|
+
customFilters: vue.Ref<Record<string, any>, Record<string, any>>;
|
|
384
396
|
};
|
|
385
397
|
|
|
386
398
|
interface NumberingOptions {
|
package/dist/index.js
CHANGED
|
@@ -103,11 +103,13 @@ function usePagination(fetchFn, options) {
|
|
|
103
103
|
const search = (0, import_vue2.ref)(options.defaultSearch || "");
|
|
104
104
|
const sortBy = (0, import_vue2.ref)(options.defaultSort?.column || null);
|
|
105
105
|
const sortDirection = (0, import_vue2.ref)(options.defaultSort?.direction || "asc");
|
|
106
|
+
const customFilters = (0, import_vue2.ref)({});
|
|
106
107
|
const filters = (0, import_vue2.computed)(() => {
|
|
107
108
|
const baseFilters = {
|
|
108
109
|
page: currentPage.value,
|
|
109
110
|
per_page: perPage.value,
|
|
110
|
-
search: search.value
|
|
111
|
+
search: search.value,
|
|
112
|
+
...customFilters.value
|
|
111
113
|
};
|
|
112
114
|
if (sortBy.value) {
|
|
113
115
|
baseFilters[`sort[${sortBy.value}]`] = sortDirection.value;
|
|
@@ -143,11 +145,15 @@ function usePagination(fetchFn, options) {
|
|
|
143
145
|
currentPage.value = 1;
|
|
144
146
|
};
|
|
145
147
|
const setFilter = (key, value) => {
|
|
146
|
-
|
|
148
|
+
customFilters.value[key] = value;
|
|
147
149
|
currentPage.value = 1;
|
|
148
150
|
};
|
|
149
151
|
const removeFilter = (key) => {
|
|
150
|
-
delete
|
|
152
|
+
delete customFilters.value[key];
|
|
153
|
+
currentPage.value = 1;
|
|
154
|
+
};
|
|
155
|
+
const handleFilterChange = (newFilters) => {
|
|
156
|
+
customFilters.value = { ...newFilters };
|
|
151
157
|
currentPage.value = 1;
|
|
152
158
|
};
|
|
153
159
|
const resetFilters = () => {
|
|
@@ -156,6 +162,7 @@ function usePagination(fetchFn, options) {
|
|
|
156
162
|
search.value = options.defaultSearch || "";
|
|
157
163
|
sortBy.value = options.defaultSort?.column || null;
|
|
158
164
|
sortDirection.value = options.defaultSort?.direction || "asc";
|
|
165
|
+
customFilters.value = {};
|
|
159
166
|
};
|
|
160
167
|
let searchTimeout;
|
|
161
168
|
(0, import_vue2.watch)(search, () => {
|
|
@@ -176,6 +183,7 @@ function usePagination(fetchFn, options) {
|
|
|
176
183
|
sortBy,
|
|
177
184
|
sortDirection,
|
|
178
185
|
filters,
|
|
186
|
+
customFilters,
|
|
179
187
|
// Query result
|
|
180
188
|
...queryResult,
|
|
181
189
|
// Computed
|
|
@@ -186,6 +194,7 @@ function usePagination(fetchFn, options) {
|
|
|
186
194
|
handlePerPageChange,
|
|
187
195
|
handleSearchChange,
|
|
188
196
|
handleSortChange,
|
|
197
|
+
handleFilterChange,
|
|
189
198
|
resetFilters,
|
|
190
199
|
setFilter,
|
|
191
200
|
removeFilter,
|
package/dist/index.mjs
CHANGED
|
@@ -76,11 +76,13 @@ function usePagination(fetchFn, options) {
|
|
|
76
76
|
const search = ref(options.defaultSearch || "");
|
|
77
77
|
const sortBy = ref(options.defaultSort?.column || null);
|
|
78
78
|
const sortDirection = ref(options.defaultSort?.direction || "asc");
|
|
79
|
+
const customFilters = ref({});
|
|
79
80
|
const filters = computed(() => {
|
|
80
81
|
const baseFilters = {
|
|
81
82
|
page: currentPage.value,
|
|
82
83
|
per_page: perPage.value,
|
|
83
|
-
search: search.value
|
|
84
|
+
search: search.value,
|
|
85
|
+
...customFilters.value
|
|
84
86
|
};
|
|
85
87
|
if (sortBy.value) {
|
|
86
88
|
baseFilters[`sort[${sortBy.value}]`] = sortDirection.value;
|
|
@@ -116,11 +118,15 @@ function usePagination(fetchFn, options) {
|
|
|
116
118
|
currentPage.value = 1;
|
|
117
119
|
};
|
|
118
120
|
const setFilter = (key, value) => {
|
|
119
|
-
|
|
121
|
+
customFilters.value[key] = value;
|
|
120
122
|
currentPage.value = 1;
|
|
121
123
|
};
|
|
122
124
|
const removeFilter = (key) => {
|
|
123
|
-
delete
|
|
125
|
+
delete customFilters.value[key];
|
|
126
|
+
currentPage.value = 1;
|
|
127
|
+
};
|
|
128
|
+
const handleFilterChange = (newFilters) => {
|
|
129
|
+
customFilters.value = { ...newFilters };
|
|
124
130
|
currentPage.value = 1;
|
|
125
131
|
};
|
|
126
132
|
const resetFilters = () => {
|
|
@@ -129,6 +135,7 @@ function usePagination(fetchFn, options) {
|
|
|
129
135
|
search.value = options.defaultSearch || "";
|
|
130
136
|
sortBy.value = options.defaultSort?.column || null;
|
|
131
137
|
sortDirection.value = options.defaultSort?.direction || "asc";
|
|
138
|
+
customFilters.value = {};
|
|
132
139
|
};
|
|
133
140
|
let searchTimeout;
|
|
134
141
|
watch(search, () => {
|
|
@@ -149,6 +156,7 @@ function usePagination(fetchFn, options) {
|
|
|
149
156
|
sortBy,
|
|
150
157
|
sortDirection,
|
|
151
158
|
filters,
|
|
159
|
+
customFilters,
|
|
152
160
|
// Query result
|
|
153
161
|
...queryResult,
|
|
154
162
|
// Computed
|
|
@@ -159,6 +167,7 @@ function usePagination(fetchFn, options) {
|
|
|
159
167
|
handlePerPageChange,
|
|
160
168
|
handleSearchChange,
|
|
161
169
|
handleSortChange,
|
|
170
|
+
handleFilterChange,
|
|
162
171
|
resetFilters,
|
|
163
172
|
setFilter,
|
|
164
173
|
removeFilter,
|