Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#6374 Tree: allow filterBy to be a getter #6367

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions apps/showcase/doc/common/apidoc/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions packages/primevue/scripts/components/tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion packages/primevue/src/tree/BaseTree.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export default {
default: false
},
filterBy: {
type: String,
type: String | ((node) => String),
default: 'label'
},
filterMode: {
Expand Down
4 changes: 2 additions & 2 deletions packages/primevue/src/tree/Tree.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions packages/primevue/src/tree/Tree.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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';

Expand Down
Loading