0

So basically I want to retrieve a results in the sales_order and display it in Admin Grid.But what I want is to retrieve the result using Group By. That way I have a unique list of Customer_email. How can I do this in Magento 2?

So basically I added these files

  • app/code/VENDOR/Module/Model/CustomModel.php
  • app/code/VENDOR/Module/Model/ResourceModel/CustomModel.php
  • app/code/VENDOR/Module/Model/ResourceModel/CustomModel/Collection.php
  • app/code/VENDOR/Module/Model/ResourceModel/CustomModel/Grid/Collection.php
  • app/code/VENDOR/Module/view/adminhtml/layout/vendormodule_custommodel.xml
  • app/code/VENDOR/Module/view/adminhtml/ui_component/vendormodule_custommodel.xml

So basically what I want is when I generate the result in my admin page the result should display all the list of customer_email, customer_name etc... and these result is grouped by customer_email. So I'm just wondering how can I customize the retrieval of collection in the Admin Grid? Like I would assume retrieval of the record is something like

select * from sales_order limit 20 or something. Now I want to override the default behaviour of the retrieval of collection and make it something like select customer_email from sales_order group by customer_email

How do I achieve this? I read someone mentioned about adding it to _prepareCollection or something but where will I put this?

Your Answer

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

Browse other questions tagged or ask your own question.