Skip to content
This repository was archived by the owner on Oct 20, 2025. It is now read-only.

Commit 4bb965f

Browse files
committed
Table custom debounce value
1 parent 7a647ac commit 4bb965f

File tree

4 files changed

+47
-10
lines changed

4 files changed

+47
-10
lines changed

lib/Components/Table.vue

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,20 @@ export default {
2727
defaultVisibleToggleableColumns: {
2828
type: Array,
2929
required: true
30+
},
31+
32+
searchDebounce: {
33+
type: Number,
34+
required: false,
35+
default: 350
3036
}
3137
},
3238
3339
data() {
3440
return {
3541
visibleColumns: [],
36-
forcedVisibleSearchInputs: []
42+
forcedVisibleSearchInputs: [],
43+
debounceUpdateQuery: null
3744
};
3845
},
3946
@@ -55,6 +62,15 @@ export default {
5562
}
5663
},
5764
65+
created() {
66+
/*
67+
* Debounces the update query.
68+
*/
69+
this.debounceUpdateQuery = debounce(function(key, value, $el) {
70+
this.updateQuery(key, value, $el);
71+
}, this.searchDebounce);
72+
},
73+
5874
mounted(){
5975
const query = this.getCurrentQuery();
6076
@@ -172,17 +188,10 @@ export default {
172188
/*
173189
* Returns a boolean whether the key should be visible.
174190
*/
175-
isForcedVisible(key){
191+
isForcedVisible(key) {
176192
return this.forcedVisibleSearchInputs.includes(key);
177193
},
178194
179-
/*
180-
* Debounces the update query with 350ms.
181-
*/
182-
debounceUpdateQuery: debounce(function(key, value, $el) {
183-
this.updateQuery(key, value, $el);
184-
}, 350),
185-
186195
/*
187196
* Parses the window's current query as an object.
188197
*/

resources/views/table/table.blade.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<SpladeTable {{ $attributes->except('class') }}
22
:striped="@js($striped)"
33
:columns="@js($table->columns())"
4+
:search-debounce="@js($searchDebounce)"
45
:default-visible-toggleable-columns="@js($table->defaultVisibleToggleableColumns())"
56
>
67
<template #default="{!! $scope !!}">

src/Components/Table.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,12 @@ public function __construct(
2020
public SpladeTable $for,
2121
public bool $striped = false,
2222
public bool $headless = false,
23-
public string $scope = 'table'
23+
public string $scope = 'table',
24+
public ?int $searchDebounce = null,
2425
) {
26+
$this->searchDebounce = is_null($searchDebounce)
27+
? SpladeTable::getDefaultSearchDebounce()
28+
: $searchDebounce;
2529
}
2630

2731
/**

src/SpladeTable.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ class SpladeTable
3737

3838
private static array $defaultPerPageOptions = [15, 30, 50, 100];
3939

40+
private static int $defaultSearchDebounce = 350;
41+
4042
/**
4143
* Creates a new instance.
4244
*
@@ -124,6 +126,27 @@ public static function defaultPerPageOptions(array $perPageOptions)
124126
static::$defaultPerPageOptions = $perPageOptions;
125127
}
126128

129+
/**
130+
* Get the default debounce value.
131+
*
132+
* @return int
133+
*/
134+
public static function getDefaultSearchDebounce(): int
135+
{
136+
return static::$defaultSearchDebounce;
137+
}
138+
139+
/**
140+
* Set a default debounce value.
141+
*
142+
* @param int $milliseconds
143+
* @return void
144+
*/
145+
public static function defaultSearchDebounce(int $milliseconds)
146+
{
147+
static::$defaultSearchDebounce = max(0, $milliseconds);
148+
}
149+
127150
/**
128151
* Set a default for global search.
129152
*

0 commit comments

Comments
 (0)