Friday, May 10, 2024
 Popular · Latest · Hot · Upcoming
20
rated 0 times [  22] [ 2]  / answers: 1 / hits: 28747  / 4 Years ago, thu, january 9, 2020, 12:00:00

If I have a user object with a display name (e.g. John Smith) and a username (e.g. johsmi), how can I search for both display name and username?



This example will only search for usernames, i.e. it will find johsmi, but not Smith:



<Select
showSearch={true}
optionFilterProp=children
placeholder=Select account
>
{users.map(user => (
<Select.Option value={user.name}>
{user.displayName}
</Select.Option>
))}
</Select>


I ended up adding the display name in the key attribute to make it searchable, but I wonder if it's the recommended way of doing it:



<Select.Option key={user.displayName} value={user.name}>
{user.displayName}
</Select.Option>

More From » reactjs

 Answers
9

Works best for me, refer this issue


<Select
allowClear
showSearch
filterOption={(inputValue, option) =>
option.children.join('').toLowerCase().includes(inputValue.toLowerCase())
}
>
{options.map(option=> (
<Option key={option.id}>{option.name}</Option>
))}
</Select>

[#51322] Tuesday, December 31, 2019, 4 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
tayaw

Total Points: 749
Total Questions: 88
Total Answers: 86

Location: Djibouti
Member since Sun, Feb 27, 2022
2 Years ago
tayaw questions
;