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

Dropdown filter does not work for array of strings #2059

Open
sid-6581 opened this issue Jan 30, 2022 · 9 comments
Open

Dropdown filter does not work for array of strings #2059

sid-6581 opened this issue Jan 30, 2022 · 9 comments
Assignees
Labels
Resolution: Needs Revision The pull request can't be merged. Conflicts need to be corrected or documentation and code updated.

Comments

@sid-6581
Copy link
Contributor

I'm submitting a ... (check one with "x")

[x] bug report => Search github for a similar issue or PR before submitting
[ ] feature request => Please check if request is not on the roadmap already https://github.com/primefaces/primevue/wiki/Roadmap
[ ] support request => Please do not submit support request here, instead see http://forum.primefaces.org/viewforum.php?f=110

CodeSandbox Case (Bug Reports)

Edit still-meadow-kov2j

Current behavior

When binding a dropdown to an array of strings and enabling filtering, typing anything in the filter box will result in no matches. Filtering only works if the dropdown is bound to an array of objects, with optionLabel set.

Expected behavior

Filtering works on array of strings as well as array of objects.

Minimal reproduction of the problem with instructions

See CodeSandbox example above.

What is the motivation / use case for changing the behavior?

Binding to an array of strings is very common, and I would expect the filtering to work in this scenario.

  • Vue version: 3.2.29

  • PrimeVue version: 3.11

  • Browser: all

@tugcekucukoglu tugcekucukoglu added the Status: Pending Review Issue or pull request is being reviewed by Core Team label Feb 1, 2022
@IvanSGurdian
Copy link

I just tried this out and was surprised to notice it didn't work with a simple array of strings, I guess we could bind a custom filter to the @filter event, but this should be something the component already handled.

@tugcekucukoglu tugcekucukoglu added Type: Bug Issue contains a bug related to a specific component. Something about the component is not working and removed Status: Pending Review Issue or pull request is being reviewed by Core Team labels Oct 20, 2022
@kayahasa
Copy link

kayahasa commented Nov 6, 2022

same issue for me also

@elliopitas
Copy link
Contributor

got the same issue too

@alex-dow
Copy link

3.29.1 also has this issue

@alex-dow
Copy link

So, it wasn't clear to me how to use the @filter event to work around this issue. Instead, I've created a wrapper component around Dropdown (and Multiselect) that will generate a list of objects if the supplied list of options are primitives.

const primitiveOptions = computed(() => {
    return !_isObject(props.values[0]);
});

const options = computed(() => {
    if (primitiveOptions.value) {
        // First item in list of available values is a string, so we should assume all values
        // are strings
        return props.values.map((v) => { return { value: v, label: v }});
    } else {
        return props.values;
    }
});

const valueField = computed(() => {
    if (primitiveOptions.value) {
        return 'value';
    } else {
        return props.valueField;
    }
});

const labelField = computed(() => {
    if (primitiveOptions.value) {
        return 'label';
    } else {
        return props.labelField;
    }
});

This gives me the behavior I expect. I can search on lists of primitives, but when I want to work with lists of objects, I get all the same flexibility.

I went this route because it seems you can't stop the default filter behavior? I'm wondering if this means I can't use the filter event for asynchronous searching.... hmm

@tugcekucukoglu tugcekucukoglu self-assigned this Oct 30, 2023
@tugcekucukoglu
Copy link
Member

This stackblitz sample seems to be working. Am I missing something?

@tugcekucukoglu tugcekucukoglu added Resolution: Needs Revision The pull request can't be merged. Conflicts need to be corrected or documentation and code updated. and removed Type: Bug Issue contains a bug related to a specific component. Something about the component is not working labels Dec 11, 2023
@zhekoff316
Copy link

I can confirm this is fixed for me - I am using 3.46.0.

@LouisVA
Copy link

LouisVA commented Aug 6, 2024

With the 4.0.0 it does not work for me (array of objects) and the component's name is "Select" now.

No difference if I put filterFields. My array of objects has objects with a 'name' field. If I put filterFields="['name']" or filterFields="name". None work.

edit: My bad, seems like I wasn't proviidng the :filterFields the right way.

@tommie
Copy link

tommie commented Aug 6, 2024

(Re. the original v3 issue, I still think #4447 solved that.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Resolution: Needs Revision The pull request can't be merged. Conflicts need to be corrected or documentation and code updated.
Projects
None yet
Development

No branches or pull requests

9 participants