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 . '%');

    }

}
  • Error occurred that name column not found. – Dhaduk Mitesh 2 days ago
  • I add this code in ui grid collection _renderFiltersBefore function. – Dhaduk Mitesh 2 days ago

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.