Skip to content

Commit

Permalink
fix(VDataTable): customKeyFilter filtering (#19881)
Browse files Browse the repository at this point in the history
fixes #19596
  • Loading branch information
lzl0304 authored May 29, 2024
1 parent f401f41 commit b3eafb2
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
54 changes: 54 additions & 0 deletions packages/vuetify/src/composables/__tests__/filter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,60 @@ describe('filter', () => {
filterMode: 'every',
})).toHaveLength(1)
})

it('should filter by mode using customKeyFilter without query', () => {
const customKeyFilter = {
title: (s: string) => s.length < 5,
value: (s: string) => s === '1',
}
const items = [
{
title: 'foo',
subtitle: 'bar',
value: '1',
},
{
title: 'fizz',
subtitle: 'buzz',
value: '1',
},
{
title: 'foobar',
subtitle: 'fizzbuzz',
value: '2',
},
{
title: 'buzz',
subtitle: 'buzz',
value: '2',
},
] as any
const filterKeys = ['title', 'value']

expect(filterItems(items, '', {
filterKeys,
customKeyFilter,
filterMode: 'some',
})).toHaveLength(3)

expect(filterItems(items, '', {
filterKeys,
customKeyFilter,
filterMode: 'union',
})).toHaveLength(2)

expect(filterItems(items, '', {
filterKeys,
customKeyFilter,
filterMode: 'intersection',
})).toHaveLength(0)

expect(filterItems(items, '', {
filterKeys,
customKeyFilter,
filterMode: 'every',
})).toHaveLength(2)
})
})

describe('useFilter', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/vuetify/src/composables/filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export function filterItems (
const defaultMatches: Record<string, FilterMatch> = {}
let match: FilterMatch = -1

if (query && !options?.noFilter) {
if ((query || customFiltersLength > 0) && !options?.noFilter) {
if (typeof item === 'object') {
const filterKeys = keys || Object.keys(transformed)

Expand Down

0 comments on commit b3eafb2

Please sign in to comment.