Tree: allow `filterBy` to be a getter

pull/6367/head
Jacob Walls 2024-09-09 16:56:48 -04:00
parent acfba694f9
commit 42f2c6f969
5 changed files with 9 additions and 9 deletions

View File

@ -65529,9 +65529,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';