Skip to content

Commit

Permalink
Merge pull request #224 from yvesh/filter-in
Browse files Browse the repository at this point in the history
Add comparsion option "in" for arrays
  • Loading branch information
HC200ok authored Feb 11, 2023
2 parents c624c42 + c46f483 commit 67ed974
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"author": "HC200ok",
"description": "A customizable and easy-to-use data table component made with Vue.js 3.x.",
"private": false,
"version": "1.5.31",
"version": "1.5.32",
"types": "./types/main.d.ts",
"license": "MIT",
"files": [
Expand Down
2 changes: 2 additions & 0 deletions src/hooks/useTotalItems.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ export default function useTotalItems(
return itemValue >= criteria;
case 'between':
return itemValue >= Math.min(...criteria) && itemValue <= Math.max(...criteria);
case 'in':
return criteria.includes(itemValue);
default:
return itemValue === criteria;
}
Expand Down
5 changes: 2 additions & 3 deletions src/modes/Client.vue
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,8 @@ const filterOptions = computed((): FilterOption[] => {
const filterOptionsArray: FilterOption[] = [];
filterOptionsArray.push({
field: 'name',
criteria: nameCriteria.value,
comparison: (value, criteria): boolean => (value != null
&& value.includes(criteria)),
criteria: ['name-1', 'name-2'],
comparison: 'in',
});
return filterOptionsArray;
});
Expand Down
6 changes: 5 additions & 1 deletion src/types/main.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export type SortType = 'asc' | 'desc'

export type FilterComparison = '=' | '!=' | '>' | '>=' | '<' | '<=' | 'between';
export type FilterComparison = '=' | '!=' | '>' | '>=' | '<' | '<=' | 'between' | 'in';

export type Item = Record<string, any>

Expand All @@ -17,6 +17,10 @@ export type FilterOption = {
comparison: '>' | '>=' | '<' | '<='
criteria: number
} | {
field: string
comparison: 'in'
criteria: number[] | string[]
}| {
field: string
comparison: (value: any, criteria: string) => boolean
criteria: string
Expand Down

0 comments on commit 67ed974

Please sign in to comment.