Showing results for 
Search instead for 
Did you mean: 

Custom multi select filter issue for the customer grid

Custom multi select filter issue for the customer grid

I've made a custom multiselect customer attribute. The attribute code is: email_preference. I've added this code to get a multiselect filter in the app/code/Vendor/Customer/view/adminhtml/ui_component/customer_listing.xml:

<?xml version="1.0" encoding="UTF-8"?>

<listing xmlns:xsi="" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
    <listingToolbar name="listing_top">
        <filters name="listing_filters">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="templates" xsi:type="array">
                        <item name="filters" xsi:type="array">
                            <item name="select" xsi:type="array">
                                <item name="component" xsi:type="string">Magento_Ui/js/form/element/ui-select</item>
                                <item name="template" xsi:type="string">ui/grid/filters/elements/ui-select</item>
    <columns name="customer_columns" class="Magento\Customer\Ui\Component\Listing\Columns">
        <column name="email_preference">
            <argument name="data" xsi:type="array">
                <item name="options" xsi:type="object">\Vendor\Customer\Model\Customer\Attribute\Source\EmailPreference</item>
                <item name="config" xsi:type="array">
                    <item name="filter" xsi:type="string">select</item>
                    <item name="dataType" xsi:type="string">select</item>
                    <item name="label" xsi:type="string" translate="true">Email preferences</item>
                    <item name="sortOrder" xsi:type="number">300</item>

In the \Vendor\Customer\Model\Customer\Attribute\Source\EmailPreference I have:

use Magento\Eav\Model\Entity\Attribute\Source\AbstractSource;

class EmailPreference extends AbstractSource
     * @return array
    public function getAllOptions(): array
        $this->_options = [];
        $this->_options[] = ['label' => 'Value1', 'value' => 'value1'];
        $this->_options[] = ['label' => 'Value2, 'value' => 'value2'];

        return $this->_options;

This filter works only if I have one value assigned to a customer. If I have multi values assinged, it will render in the grid like this: Value1,Value2, however If I select Value1 and Value2 from the filter , I will only get customers with one values assigned. Either Value1 or Value2 , but not Value1,Value. For example, in this case, if I select Value1 and Value2 from the multiselect:

Customer 1 -> Value1
Customer 2 -> Value2
Customer 3 -> Value1,Value2

I will get only Customer 1 and Customer 2, not Customer 3. How can I change my filter to make this work ? or What am I missing ?

Thanks a lot!


Re: Custom multi select filter issue for the customer grid

try making your column multiselect instead of select <item name="dataType" xsi:type="string">multiselect</item>. Not sure if it works, but it's easy to test