mirror of
https://github.com/BlossomiShymae/clean-cuts.git
synced 2025-12-06 18:20:47 +01:00
Add id and text search
This commit is contained in:
18
composables/useQueryablePagination.ts
Normal file
18
composables/useQueryablePagination.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
|
||||
const isNumeric = (num: any) => (typeof(num) === 'number' || typeof(num) === "string" && num.trim() !== '') && !isNaN(num as number);
|
||||
|
||||
export default function useQueryablePagination<T>(iterable: Array<T>, pageSize: number, query: Ref<string>) {
|
||||
const pagination = computed(() => {
|
||||
let filtered = [];
|
||||
if (isNumeric(query.value))
|
||||
filtered = iterable.filter((x: any) => x.id == parseInt(query.value, 10));
|
||||
else
|
||||
filtered = iterable.filter((x) => x.title.toLowerCase().includes(query.value.toLowerCase()));
|
||||
|
||||
return usePagination(icons, 100);
|
||||
})
|
||||
|
||||
return {
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user