3

I created a custom Ui-component grid having one column customer_id.

For Customer_id I created a renderer class that gets the name of customer through customer_id.

uicomponennt Column

        <column name="customer_id" class="Ced\CsMarketplace\Ui\Component\Listing\Column\Vendoremail">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="bodyTmpl" xsi:type="string">ui/grid/cells/html</item>
                    <item name="filter" xsi:type="string">text</item>
                    <item name="label" xsi:type="string" translate="true">Vendor Email</item>
                </item>
            </argument>                                              
        </column>

now When i use filter for this column. it posts customer_id.

I want to search on customer email-id text.

7
  • I am also looking for similar thing
    – Ashish Raj
    Commented May 15, 2018 at 11:03
  • @AshishRaj You can do it by call back in your model collection file. there you can get customer_id and based on that you can write your custom logic. Commented May 15, 2018 at 11:12
  • yes I am able to show the customer name or email by using id but how to use filter for that fields...
    – Ashish Raj
    Commented May 15, 2018 at 11:34
  • 1
    Can you show me a code example... it will be great for me, thanks
    – Ashish Raj
    Commented May 15, 2018 at 12:56
  • 1
    Can you please help me here? magento.stackexchange.com/q/296226 Commented Nov 20, 2019 at 7:19

1 Answer 1

3

In your Model Collection file you can use _renderFiltersBefore() method. like below i used.

protected function _renderFiltersBefore() {

        $filters = $this->request->getParam('filters');
        if (isset($filters['customer_id'])) { // your filter index in which you want filter callback
            $objectManager = \Magento\Framework\App\ObjectManager::getInstance();

            $customers = $objectManager->get('My\Custom\Model\MyModel')->create()
                    ->getCollection()
                    ->addAttributeToFilter('email', ['like' => '%' . $filters['customer_id'] . '%']);

            $customer_id = array();

            foreach ($customers as $customer) {
                $customer_id[] = $customer->getId();
                $this->getSelect()->orWhere("main_table.customer_id = '" . $customer->getId() . "'");
            }
        }
        
        parent::_renderFiltersBefore();
}

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.