By default Tree select of Ant design search by value, is there a way to search by title?
I have tried using onSearch function but it doesn't change any behavior of Tree Select
By default Tree select of Ant design search by value, is there a way to search by title?
I have tried using onSearch function but it doesn't change any behavior of Tree Select
Just to elaborate on the answer provided by @Oliver, you can add the following props:
<TreeSelect
showSearch
treeNodeFilterProp='title'
treeData={treeData}
...
/>
You can use the filterTreeNode prop to provide a custom filter function, but for standard functionality it should not be needed.
You can search by title, or any other fields of your treeData item, there is a callback prop filterTreeNode for that purpose
Example:
<TreeSelect
treeData={data}
filterTreeNode={(search, item) => {
return item.title.toLowerCase().indexOf(search.toLowerCase()) >= 0;
}}
/>
There's actually a better and simpler way to do it by providing treeNodeFilterProp, which is directly used for filtering. Its default value is 'value' and you can simply change it to 'title' to achieve the desired behaviour.