I am trying to add a custom column in my custom grid in the admin panel. To add the custom column, I have used LEFT JOIN and GROUP BY in the collection which I get from the parent grid class.

After using JOIN and GROUP BY clauses, I am able to add the custom column in my grid, but the issue is that the GRID is now showing the wrong count of records always.

It is always showing 1 as count.

I have added the same column in another grid and it is working fine.

Note: I am not using UI component. Since the grid is coming from an extension's block files, I am using block PHP file to add my custom column.

Wrong Count

Please help.

  • You got any solution for this? – amesh Oct 24 '18 at 6:41
  • @amesh, I have posted my solution. Please check and hit upvote if it works for you. – Mohit Kumar Arora Oct 24 '18 at 7:02

After some research, I found the solution.

Below is my approach to fixing the count:

Create or open app/code/[Namespace]/[Module]/Model/ResourceModel/[ModelClassFolder]/Collection.php

and paste code like below:


namespace [Namespace]\[Module]\Model\ResourceModel\[ModelClassFolder];

class Collection extends \Magento\Catalog\Model\ResourceModel\Product\Collection
    public function getSelectCountSql() {
        $countSelect = parent::getSelectCountSql();
        return $countSelect;

Note: You need to change Namespace, Module, ModelClassFolder and the class after extends.

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.