javascriptreactjsfrontendant-design-pro

Search Ant Design Tree Select by Title


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


Solution

  • 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;
          }}
    />