Skip to content

Commit

Permalink
Merge pull request #6367 from jacobtylerwalls/tree-filter-by-getter
Browse files Browse the repository at this point in the history
#6374 Tree: allow `filterBy` to be a getter
  • Loading branch information
tugcekucukoglu authored Sep 24, 2024
2 parents e4d431e + 42f2c6f commit 74074bc
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 9 deletions.
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 @@ -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",
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),

Check failure on line 46 in packages/primevue/src/tree/BaseTree.vue

View workflow job for this annotation

GitHub Actions / build (18)

The "filterBy" property should be a constructor

Check failure on line 46 in packages/primevue/src/tree/BaseTree.vue

View workflow job for this annotation

GitHub Actions / build (20)

The "filterBy" property should be a constructor
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

0 comments on commit 74074bc

Please sign in to comment.