Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exclude item from search #265

Open
PaviSF opened this issue Apr 29, 2024 · 1 comment
Open

Exclude item from search #265

PaviSF opened this issue Apr 29, 2024 · 1 comment

Comments

@PaviSF
Copy link

PaviSF commented Apr 29, 2024

How to exclude an item from search? I have added two headers to categorize the list and when i search for an item the headers are also getting searched?

const data = [
  { label: 'Sports', value: '1', disabled: true },
  { label: 'Football', value: '2', disabled: false },
  { label: 'Cricket', value: '3', disabled: false },
  { label: 'Plans', value: '4', disabled: true },
  { label: 'Plan A', value: '5', disabled: false },
  { label: 'Plan B', value: '6', disabled: false },
  { label: 'Plan C', value: '7', disabled: false },
  { label: 'Plan D', value: '8', disabled: false },
];

const DropdownComponent = () => {
  const [value, setValue] = useState(null);

  const renderItem = (item) => {
    if (item.disabled)
      return (
        <Text onPress={(event) => event.preventDefault()} style={styles.header}>
          {item.label}
        </Text>
      );
    return (
      <View
        style={[
          styles.item,
          { backgroundColor: item.value === value ? 'red' : 'white' },
        ]}>
        <Text style={styles.textItem}>{item.label}</Text>
      </View>
    );
  };
  ``;

  return (
    <Dropdown
      data={data}
      search
      labelField="label"
      valueField="value"
      placeholder="Select item"
      searchPlaceholder="Search..."
      value={value}
      onChange={(item) => {
        setValue(item.value);
      }}
      renderItem={renderItem}
    />
  );
};
@hoaphantn7604
Copy link
Owner

Hi @PaviSF ,

I have added the props excludeSearchItems. You can pass in a list of items to be excluded from the search.
Don't forget to update to the latest version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants