Merge pull request #6367 from jacobtylerwalls/tree-filter-by-getter

#6374 Tree: allow `filterBy` to be a getter
pull/6465/head
Tuğçe Küçükoğlu 2024-09-24 08:48:44 +03:00 committed by GitHub
commit 74074bc020
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 9 additions and 9 deletions

View File

@ -65772,9 +65772,9 @@
"name": "filterBy",
"optional": true,
"readonly": false,
"type": "string",
"type": "string | ((node: TreeNode) => string)",
"default": "label",
"description": "When filtering is enabled, filterBy decides which field or fields (comma separated) to search against."
"description": "When filtering is enabled, filterBy decides which field or fields (comma separated) to search against. A callable taking a TreeNode can be provided instead of a list of field names."
},
{
"name": "filterMode",

View File

@ -50,9 +50,9 @@ const TreeProps = [
},
{
name: 'filterBy',
type: 'string',
type: 'string | ((node: TreeNode) => string)',
default: 'label',
description: 'When filtering is enabled, filterBy decides which field or fields (comma separated) to search against.'
description: 'When filtering is enabled, filterBy decides which field or fields (comma separated) to search against. A callable taking a TreeNode can be provided instead of a list of field names.'
},
{
name: 'filterMode',

View File

@ -43,7 +43,7 @@ export default {
default: false
},
filterBy: {
type: String,
type: String | ((node) => String),
default: 'label'
},
filterMode: {

View File

@ -277,10 +277,10 @@ export interface TreeProps {
*/
filter?: boolean | undefined;
/**
* When filtering is enabled, filterBy decides which field or fields (comma separated) to search against.
* When filtering is enabled, filterBy decides which field or fields (comma separated) to search against. A callable taking a TreeNode can be provided instead of a list of field names.
* @defaultValue label
*/
filterBy?: string | undefined;
filterBy?: string | ((node: TreeNode) => string) | undefined;
/**
* Mode for filtering.
* @defaultValue lenient

View File

@ -42,7 +42,7 @@
</template>
<script>
import { resolveFieldData } from '@primeuix/utils/object';
import { isFunction, resolveFieldData } from '@primeuix/utils/object';
import SearchIcon from '@primevue/icons/search';
import SpinnerIcon from '@primevue/icons/spinner';
import IconField from 'primevue/iconfield';
@ -222,7 +222,7 @@ export default {
computed: {
filteredValue() {
let filteredNodes = [];
const searchFields = this.filterBy.split(',');
const searchFields = isFunction(this.filterBy) ? [this.filterBy] : this.filterBy.split(',');
const filterText = this.filterValue.trim().toLocaleLowerCase(this.filterLocale);
const strict = this.filterMode === 'strict';