{"id":1558,"date":"2021-01-29T11:06:55","date_gmt":"2021-01-29T11:06:55","guid":{"rendered":"https:\/\/meetanshi.com\/blog\/add-inline-edit-in-ui-grid-in-magento-2-backend\/"},"modified":"2025-07-17T10:05:16","modified_gmt":"2025-07-17T04:35:16","slug":"add-inline-edit-in-ui-grid-in-magento-2-backend","status":"publish","type":"post","link":"https:\/\/meetanshi.com\/blog\/add-inline-edit-in-ui-grid-in-magento-2-backend\/","title":{"rendered":"How to Add Inline Edit in UI Grid in Magento 2 Backend"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">The Magento 2 UI grids are used to manage the store data in an easy-to-handle format.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In default\u00a0Magento 2, the backend grids allow the admin to sort, filter, and edit the data. The admin can also use pagination and mass action to update the data in bulk.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">However, there is a drawback in the design of the grids that compels the admin to open each row and update the data in it. It is a tedious and time-consuming task.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The solution to this issue is to add inline edit in UI grid in Magento 2 backend as shown below:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/meetanshi.com\/blog\/wp-content\/uploads\/2021\/01\/SS-blog-1024x143.jpg\" alt=\"inline edit\" class=\"wp-image-12817\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">After implementing it using the below solution, the admin need not open each entry in the edit mode but simply make the necessary changes using the inline edit as shown in the above image.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You can use this solution in&nbsp;<a href=\"https:\/\/meetanshi.com\/blog\/create-admin-grid-magento-2\/\" target=\"_blank\" rel=\"noreferrer noopener\">a custom admin grid<\/a>&nbsp;as well as in Magento 2 default grids.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Steps to Add Inline Edit in UI Grid in Magento 2 Backend<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">1. Use the below code in your&nbsp;<strong>xml<\/strong>&nbsp;file of&nbsp;<strong>ui_component&nbsp;<\/strong>or in the grid where you want to add inline edit.<br>This file will be located under&nbsp;&nbsp;<strong><strong>Vendor\/Extension\/view\/adminhtml\/ui_component\/ .<\/strong><\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;columns name=\"data_records_columns\">\n    &lt;settings>\n        &lt;editorConfig>\n            &lt;param name=\"clientConfig\" xsi:type=\"array\">\n                &lt;item name=\"saveUrl\" xsi:type=\"url\" path=\"routes\/action\/inlineedit\"\/>\n                &lt;item name=\"validateBeforeSave\" xsi:type=\"boolean\">false&lt;\/item>\n            &lt;\/param>\n            &lt;param name=\"indexField\" xsi:type=\"string\">\n                entity_id\n            &lt;\/param>\n            &lt;param name=\"enabled\" xsi:type=\"boolean\">\n                true\n            &lt;\/param>\n            &lt;param name=\"selectProvider\" xsi:type=\"string\">\n                data_list.data_list.data_records_columns.ids\n            &lt;\/param>\n        &lt;\/editorConfig>\n        &lt;childDefaults>\n            &lt;param name=\"fieldAction\" xsi:type=\"array\">\n                &lt;item name=\"provider\" xsi:type=\"string\">data_list.data_list.data_records_columns_editor&lt;\/item>\n                &lt;item name=\"target\" xsi:type=\"string\">startEdit&lt;\/item>\n                &lt;item name=\"params\" xsi:type=\"array\">\n                    &lt;item name=\"0\" xsi:type=\"string\">${ $.$data.rowIndex }&lt;\/item>\n                    &lt;item name=\"1\" xsi:type=\"boolean\">true&lt;\/item>\n                &lt;\/item>\n            &lt;\/param>\n        &lt;\/childDefaults>\n    &lt;\/settings>\n    &lt;selectionsColumn name=\"ids\">\n        &lt;argument name=\"data\" xsi:type=\"array\">\n            &lt;item name=\"config\" xsi:type=\"array\">\n                &lt;item name=\"indexField\" xsi:type=\"string\">entity_id&lt;\/item>\n                &lt;item name=\"sortOrder\" xsi:type=\"number\">0&lt;\/item>\n            &lt;\/item>\n        &lt;\/argument>\n    &lt;\/selectionsColumn>\n\/\/name of a column on which you want to add inline edit\n    &lt;column name=\"name\">\n        &lt;argument name=\"data\" xsi:type=\"array\">\n            &lt;item name=\"config\" xsi:type=\"array\">\n                &lt;item name=\"component\" xsi:type=\"string\">Magento_Ui\/js\/grid\/columns\/column&lt;\/item>\n                &lt;item name=\"editor\" xsi:type=\"array\">\n                    &lt;item name=\"editorType\" xsi:type=\"string\">text&lt;\/item>\n                    &lt;item name=\"validation\" xsi:type=\"array\">\n                        &lt;item name=\"name\" xsi:type=\"boolean\">true&lt;\/item>\n                    &lt;\/item>\n                &lt;\/item>\n                &lt;item name=\"label\" xsi:type=\"string\" translate=\"true\">Name&lt;\/item>\n                &lt;item name=\"dataType\" xsi:type=\"string\">text&lt;\/item>\n                &lt;item name=\"sortOrder\" xsi:type=\"number\">50&lt;\/item>\n                &lt;item name=\"resizeEnabled\" xsi:type=\"boolean\">false&lt;\/item>\n                &lt;item name=\"resizeDefaultWidth\" xsi:type=\"string\">60&lt;\/item>\n                &lt;item name=\"sortable\" xsi:type=\"boolean\">false&lt;\/item>\n            &lt;\/item>\n        &lt;\/argument>\n    &lt;\/column>\n&lt;\/columns><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">2. Create the&nbsp;<strong>InlineEdit.php<\/strong>&nbsp;file to get data and save it in the database at&nbsp;<strong><strong>Vendor\/Extension\/Controller\/Adminhtml\/Action\/.<\/strong><\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?php\n\nnamespace Vendor\\Extension\\Controller\\Adminhtml\\Action;\n\nuse Magento\\Backend\\App\\Action;\nuse Magento\\Backend\\App\\Action\\Context;\nuse Magento\\Framework\\Controller\\Result\\JsonFactory;\nuse Vendore\\Extension\\Model\\Model;\n\nclass InlineEdit extends Action\n{\n    protected $jsonFactory;\n    protected $model;\n\n    public function __construct(\n        Context $context,\n        JsonFactory $jsonFactory,\n        Model $model\n    )\n    {\n        parent::__construct($context);\n        $this->jsonFactory = $jsonFactory;\n        $this->model = $model;\n    }\n\n    public function execute()\n    {\n        $resultJson = $this->jsonFactory->create();\n        $error = false;\n        $messages = [];\n        if ($this->getRequest()->getParam('isAjax')) {\n            $postItems = $this->getRequest()->getParam('items', []);\n            if (empty($postItems)) {\n                $messages[] = __('Please correct the data sent.');\n                $error = true;\n            } else {\n                foreach (array_keys($postItems) as $entityId) {\n                    $modelData = $this->model->load($entityId);\n                    try {\n                        $modelData->setData(array_merge($modelData->getData(), $postItems[$entityId]));\n                        $modelData->save();\n                    } catch (\\Exception $e) {\n                        $messages[] = \"[Error:]  {$e->getMessage()}\";\n                        $error = true;\n                    }\n                }\n            }\n        }\n\n        return $resultJson->setData([\n            'messages' => $messages,\n            'error' => $error\n        ]);\n    }<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Done!<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Feel free to share the solution with Magento Community via social media.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Thank You.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The Magento 2 UI grids are used to manage the store data in an easy-to-handle format. In default\u00a0Magento 2, the backend grids allow the admin&#8230;<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[34],"tags":[],"class_list":["post-1558","post","type-post","status-publish","format-standard","hentry","category-magento"],"acf":[],"_links":{"self":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/1558","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/comments?post=1558"}],"version-history":[{"count":3,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/1558\/revisions"}],"predecessor-version":[{"id":14527,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/1558\/revisions\/14527"}],"wp:attachment":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/media?parent=1558"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/categories?post=1558"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/tags?post=1558"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}