5

I want to create an admin grid.
Taking the reference to https://www.mageplaza.com/magento-2-module-development/create-admin-grid-magento-2.html, I can see there are following two ways :

  1. Using Component
  2. Using Layout

My question here is which one is better and why?

1 Answer 1

20

Each approach has upsides and downsides.
I suggest using the ui-components one because this is where Magento 2 is going right now.
The layouts and blocks approach is just legacy from the M1 version.

But let's take them separately:

Ui Components

  • (+) It's mostly configuration. So you write less code, so less code that can break
  • (+) you get a cool grid with show/hide columns, full text search, inline edit, export built in and maybe others.
  • (+) It can easily be extended with just another xml file in a different module
  • (+) any new feature magento rolls out for the grids you will get it automatically in your grid.
  • (-) Difficult to debug
  • (-) Difficult to build non standard grids
  • (-) Not very much control over what happens

Layout files and blocks:

  • (+) You got full control of what happens.
  • (+) Relatively easy to build non-standard grids.
  • (+) Easy to debug
  • (+) You can use your knowledge from M1 to do it.
  • (-) Grid is not that flexible or extensible.
  • (-) you need to write the same code over and over again.
  • (-) More code to test or that can break

That's all I have so far. The lists are far from being complete.

1
  • Can we develop specific records export csv functionality via layout grid in M2? Like this: prnt.sc/1xdrekr
    – Yogita
    Oct 26, 2021 at 13:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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