2

How to get Customer collection filter by Full name or by keyword like admin grid of magento 2?

enter image description here

1

First, you have to call the Customer Collection factory and after that add addNameToSelect() function to that collection.

namespace {nameSpace};


class CustomCollection
{
    protected  $collectionFactory;
    public function __construct(
        \Magento\Customer\Model\ResourceModel\Customer\CollectionFactory $collectionFactory
    )
    {
        $this->collectionFactory = $collectionFactory;
    }

    public function getCustomCollectionWithFullName()
    {
        $customerName = 'John';
        $customerCollection = $this->collectionFactory->create();
        $customerCollection->addAttributeToSelect('*'); // use * for all field
        $customerCollection->addNameToSelect();
        // for == condition
        $customerCollection->getSelect() ->where(
            'name = ?',
            $customerName
        );
        // where like %V%

       // $customerCollection->where('name LIKE ?', '%' . $customerName . '%');

    }

}
|improve this answer|||||
  • Error occurred that name column not found. – Dhaduk Mitesh Dec 10 '19 at 12:04
  • I add this code in ui grid collection _renderFiltersBefore function. – Dhaduk Mitesh Dec 10 '19 at 12:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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