I have a customer column in my custom module admin grid (created using UI component) where I show the customer name. But in database I save customer Id. I need to use the filter on customer name as input box in my grid filters. When I filter the grid by customer ID it works fine.

My question is how I can filter it by using customer name? Same as we do in Magento 1 using filter_condition_callback.


3 Answers 3


Yes. If one wants to join eav_attribute_option_value table to filtering option value, one can use below code.

            'header' => __('Manufacturer'),
            'index' => 'manufacturer',
            'filter_condition_callback' => [$this, 'filterCustomManufacturer'],
            'header_css_class' => 'col-manufacturer',
            'column_css_class' => 'col-manufacturer'

Below add filter condition callback function including joins like,

protected function filterCustomManufacturer($collection, $column)
    if (!$value = $column->getFilter()->getValue()) {
        return $this;

    'e.row_id = c_p_e_i.row_id',array('value'));

    'c_p_e_i.value = attribute_option.option_id and attribute_option.store_id = 0',
     array('eaov_val'=>'value' , 'eaov_option'=>'option_id'));

     $collection->getSelect()->where("`attribute_option`.`value` like ?", "%$value%");

    return $this;

Please check

Magento 2 : How can I load an admin grid with pre-defined filter values?

U have to apply

<item name="filter_url_params" xsi:type="array">
   <item name="customer_id" xsi:type="string">*</item>

& follow for code. Check in URL it's passing or not.


U need to add prepareUpdateUrl() function

  • I am using UI component for this. So where I need to define the _addColumnFilterToCollection ? Commented May 11, 2017 at 7:01
  • It's a different function. U can define after/before _prepareCollection(). Can print query for log
    – Jackson
    Commented May 11, 2017 at 7:04
  • I didn't used file CompanyName\ModuleName\Block\Adminhtml\Custom\Edit\Tab\Grid.php for fetching collection. Rather I have used CompanyName\ModuleName\Model\ResourceModel\Custom\Grid\Collection.php which extends ...\ResourceModel\Custom\Collection.php and fetching the collection from there. Could you tell me the path where should I write those functions? Commented May 11, 2017 at 7:21
  • U r using .xml file for listing?
    – Jackson
    Commented May 11, 2017 at 7:23
  • Yes as mentioned in question I am using ui-component in .xml. Commented May 11, 2017 at 7:24

I have solved the problem by joining my custom module collection with 'customer_grid_flat' table.

In Vendor\ModuleName\Model\ResourceModel\ModuleName\Collection.php

    protected function _renderFiltersBefore()
    $joinTable = $this->getTable('customer_grid_flat');
    $this->getSelect()->joinleft($joinTable.' as customer','main_table.customer_id = customer.entity_id', array('name'=> 'name'));

And in Uicomponent xml Vendor/ModuleName/view/adminhtml/ui_component/custom_module_listing.xml added column for field 'name'

    <column name="name">
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="filter" xsi:type="string">text</item>
                <item name="label" xsi:type="string" translate="true">Customer Name</item>
                <item name="dataType" xsi:type="string">text</item>
  • Doesn't work if you already have name column in the main table (or, for example, join yet another table that has name column). Commented Nov 28, 2017 at 10:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.