Tree: allow `filterBy` to be a getter
parent
acfba694f9
commit
42f2c6f969
|
@ -65529,9 +65529,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",
|
||||||
|
|
|
@ -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',
|
||||||
|
|
|
@ -43,7 +43,7 @@ export default {
|
||||||
default: false
|
default: false
|
||||||
},
|
},
|
||||||
filterBy: {
|
filterBy: {
|
||||||
type: String,
|
type: String | ((node) => String),
|
||||||
default: 'label'
|
default: 'label'
|
||||||
},
|
},
|
||||||
filterMode: {
|
filterMode: {
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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';
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue