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

Filters: Allow filters on primitive arrays #3375

Closed
bhkangw opened this issue Sep 28, 2022 · 7 comments · Fixed by #3380
Closed

Filters: Allow filters on primitive arrays #3375

bhkangw opened this issue Sep 28, 2022 · 7 comments · Fixed by #3380
Assignees
Labels
Type: New Feature Issue contains a new feature or new component request
Milestone

Comments

@bhkangw
Copy link

bhkangw commented Sep 28, 2022

Describe the feature you would like to see added

Is it possible to add filterable dropdowns within DataTable filter templates? Dropdown's filterBy prop can be specified to match by name, label, etc but what about when options must be strings in the case of filter templates?

const statuses = [
    "unqualified",
    "qualified",
    "new",
    "negotiation",
    "renewal",
    "proposal"
];

const statusFilterTemplate = (options) => {
   return (
      <Dropdown
        value={options.value}
        options={statuses}
        onChange={(e) => options.filterCallback(e.value, options.index)}
        itemTemplate={statusItemTemplate}
        placeholder="Select a Status"
        className="p-column-filter"
        showClear
        filter
        filterBy="name" // this doesn't work as DataTable filter templates only accept options as strings
      />
   );
};

Is your feature request related to a problem?

In a column with many options, it is useful to give the user the option to type and filter through the dropdown like one may expect anywhere else.

Describe the solution you'd like

The ability to use filterBy prop in Dropdown even when options is a list of strings rather than object.

Perhaps an option to set filterBy="string" or leave filterBy unset which defaults to searching for un-nested strings in the options list.

Additional context

Here's a codesandbox with a simplified DataTable and the filterBy prop under Status column displaying the proper UI -- but not matching when you type in any valid status

@bhkangw bhkangw added Status: Discussion Issue or pull request needs to be discussed by Core Team Type: New Feature Issue contains a new feature or new component request labels Sep 28, 2022
@github-actions github-actions bot added the Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible label Sep 28, 2022
@melloware
Copy link
Member

I don't understand your code sandbox is working for me. If I pick "qualified" in the Status dropdown filter it filters by Qualified?

image

@melloware melloware changed the title Add filterable dropdowns within DataTable filter templates Datatable: Add filterable dropdowns within filter templates Sep 28, 2022
@bhkangw
Copy link
Author

bhkangw commented Sep 28, 2022

Thanks @melloware - it's not that you can't select it. But with the filter & filterBy prop enabled for Dropdown you should be able to "filter" the dropdown options by typing. For example, typing in "qua" should filter out all the options but Qualified

@bhkangw
Copy link
Author

bhkangw commented Sep 28, 2022

Hi @melloware I updated the code sandbox with a separate Country dropdown to demonstrate the differences.

You can filter countries successfully within the dropdown menu
Screen Shot 2022-09-28 at 9 22 46 AM

But the status options never return a match
Screen Shot 2022-09-28 at 9 22 16 AM

@melloware
Copy link
Member

AHHH OK now i understand what you are asking for. :)

melloware added a commit to melloware/primereact that referenced this issue Sep 28, 2022
@melloware melloware removed Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible Status: Discussion Issue or pull request needs to be discussed by Core Team labels Sep 28, 2022
@melloware melloware self-assigned this Sep 28, 2022
@melloware melloware added this to the 8.6.2 milestone Sep 28, 2022
@melloware
Copy link
Member

OK with my fix in 8.6.2 you only need to add filter to Dropdown for primitive strings and it will filter the primitive strings. You can add filterBy it will just be ignored if I detect the value is just a String

@bhkangw
Copy link
Author

bhkangw commented Sep 28, 2022

@melloware I gotta say I am SUPER impressed by PrimeReact and your speed & effort

Thank you so much!!!

@melloware
Copy link
Member

Thanks for the report! I agree it should definitely support native strings and the fix was pretty easy!

@melloware melloware changed the title Datatable: Add filterable dropdowns within filter templates Filters: Allow filters on primitive arrays Oct 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: New Feature Issue contains a new feature or new component request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants