PluginProbe
The Innovative Form Builder – IvyForms / 1.1
The Innovative Form Builder – IvyForms v1.1
1.5.1 1.5 1.4.1 1.4 trunk 0.1.2 0.2 0.2.1 0.3 0.3.1 0.4 0.5 0.6 0.6.1 0.6.1-backup 0.6.1.1 0.7 0.8 0.8.1 0.8.2 0.9 0.9.1 1.0 1.1 1.1.1 All 27 releases
ivyforms / frontend / src / views / _components / table / composables / useTableSearch.ts

useTableSearch.ts in The Innovative Form Builder – IvyForms 1.1, at frontend/src/views/_components/table/composables/useTableSearch.ts

33 lines 819 B
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { onBeforeUnmount, ref, watch } from 'vue'
2 import { debounce } from 'lodash'
3
4 export interface UseTableSearchOptions {
5 delay?: number
6 initial?: string
7 }
8
9 export function useTableSearch(options: UseTableSearchOptions = {}) {
10 const { delay = 500, initial = '' } = options
11
12 const searchQuery = ref<string>(initial)
13 const debouncedSearchQuery = ref<string>(initial)
14
15 const updateDebouncedSearch = debounce((value: string) => {
16 debouncedSearchQuery.value = value
17 }, delay)
18
19 watch(searchQuery, (value) => updateDebouncedSearch(value))
20
21 const clearSearch = () => {
22 updateDebouncedSearch.cancel()
23 searchQuery.value = ''
24 debouncedSearchQuery.value = ''
25 }
26
27 onBeforeUnmount(() => {
28 updateDebouncedSearch.cancel()
29 })
30
31 return { searchQuery, debouncedSearchQuery, clearSearch }
32 }
33