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", "name": "filterBy",
"optional": true, "optional": true,
"readonly": false, "readonly": false,
"type": "string", "type": "string | ((node: TreeNode) => string)",
"default": "label", "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", "name": "filterMode",

View File

@ -50,9 +50,9 @@ const TreeProps = [
}, },
{ {
name: 'filterBy', name: 'filterBy',
type: 'string', type: 'string | ((node: TreeNode) => string)',
default: 'label', 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', name: 'filterMode',

View File

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

View File

@ -277,10 +277,10 @@ export interface TreeProps {
*/ */
filter?: boolean | undefined; 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 * @defaultValue label
*/ */
filterBy?: string | undefined; filterBy?: string | ((node: TreeNode) => string) | undefined;
/** /**
* Mode for filtering. * Mode for filtering.
* @defaultValue lenient * @defaultValue lenient

View File

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