Creating magento2 adminhtml grid

Magento2 provides an infrastructure, Adminhtml Grid, for you to do the admin backend development in an elegant way. In this article, I’ll introduce you the mechanism of the Adminhtml Grid and you’ll know how to manage the data through it easily and efficiently.

If you miss my previous magento2 related article, take a look from here.

Suppose Namespace : SR and Module : Weblog

Get a copy of this module? Download from here

20 thoughts on “Creating magento2 adminhtml grid

  1. hi,
    i have install this but giving error on grid as “\SR\Weblog\Model\BlogPostsFactory” is not there in the module on github. can you tell me what should this file contains?

  2. Hi,

    I have fallowed your article it’s working fine.

    Can you please let me know how to override adminhtml .phtml files? If possible give a simple example.


  3. For filtering telephone (custom column added) number in my order grid, I’m using the following code.
    protected function _initSelect()
    [‘addressTable’ => $this->getTable(‘sales_order_address’)],
    ‘main_table.entity_id= addressTable.parent_id’,

    But it is returning me the following error.
    Item (Magento\Framework\View\Element\UiComponent\DataProvider\Document) with the same ID “1” already exists.

    Any idea what’s going wrong here?

    Thanks in advance.

    1. That means your collection has duplicate id. So add group by in your query.Like $this->getSelect()->group(‘main_table.entity_id’ );

      1. Yes it is duplicating it because parent_id exists for billing and shipping addresses. I think I need to add where clause for addressTable.address_type = ‘billing’ since telephone number from billing address is required. How can I check this using magento2 ORM in following query

        $this->getSelect()->joinLeft (
        [‘addressTable’ => $this->getTable(‘sales_order_address’)],
        ‘main_table.entity_id= addressTable.parent_id’,

  4. Issue resolved with this. Thanks bro

    [‘addressTable’ => $this->getTable(‘sales_order_address’)],
    ‘main_table.entity_id = addressTable.parent_id’,
    ‘address_type’ => ‘addressTable.address_type’,
    ‘telephone’ => ‘addressTable.telephone’
    )->where( “address_type = ‘billing'” );

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.