carbon-design-system / carbon-website

The website for the Carbon Design System.
https://www.carbondesignsystem.com
Apache License 2.0
283 stars 785 forks source link

Filtering Dropdowns/MultiSelect & Tables for React components #997

Closed OmarSherif96 closed 4 years ago

OmarSherif96 commented 4 years ago

Hello, How can I add a filter option to these components ? I read the docs and checked github issues but I can't find it.

I tried embedding the Search component as well in the Dropdown but it doesn't work.

Can someone please provide a working example of how to filter lists/tables ?

Thanks

jnm2377 commented 4 years ago

Hi, you can view an example of our filterable multiselect here: https://www.carbondesignsystem.com/components/dropdown/code#filterable-multiselect You simply have to use <MultiSelect.Filterable/> rather than just MultiSelect.

As for the data table, there's a prop that is used to filter rows, although it has a default filter already. If you wanna customize the filtering, though, you can do that with the filterRows prop.

Screen Shot 2020-03-10 at 2.39.56 PM.png

You can view the working example here: https://react.carbondesignsystem.com/?path=/story/datatable--with-batch-actions Whatever you type into the search bar will be filtered.

Screen Shot 2020-03-10 at 2.42.20 PM.png

Does that help?

OmarSherif96 commented 4 years ago

Hello Josefina, Thanks that works for the Multiselect and Tables.

But I have two questions: 1) Does this feature exist in the Dropdown ? 2) How can I use the Search component, like passing a data props to it so it can be able to search for it ? it's not clear in the docs.

jnm2377 commented 4 years ago

@OmarSherif96 the Dropdown component doesn't support filtering or search. The ComboBox component is like dropdown but with filtering. https://react.carbondesignsystem.com/?path=/story/combobox--default It's like dropdown in that you can only select one option, but has filtering like the multiselect.