0

I have loaded the widget block form grid in the edit product section.

I am trying to open the model popup in the adminhtml widget grid form.

I have added the action column like below

$this->addColumn('action', array(
                'header' => __('Action'),
                'width' => '50',
                'type' => 'action',
                'getter' => 'getProductId',
                'actions' => array(
                    array(
                        'caption' => __('Add Content'),
                        'url' => array('base' => 'catalog/product/edit'),
                        'target'=>'_blank',
                        'field' => 'id'
                    )
                ),
                
        ));

Action column added in my grid but now I want to open the slider model popup or normal model popup with form on click of add content link,

I also tried to load with the renderer method but unable to load it.

Could anyone suggest how to achieve this?

1 Answer 1

1

To open a modal popup with a form when clicking on the "Add Content" link in the action column of your widget grid, you'll need to make a few modifications.

First, update the 'actions' array in your column definition to include a 'popup' key with the value set to true. This will ensure that the link opens in a modal popup:

'actions' => array(
    array(
        'caption' => __('Add Content'),
        'url' => array('base' => 'catalog/product/edit'),
        'target' => '_blank',
        'field' => 'id',
        'popup' => true // Open in a modal popup
    )
),

Next, you'll need to define a renderer for the action column to handle the opening of the modal. You can do this by adding a 'renderer' key with a value representing the class that will render the column content:

'renderer' => 'Vendor\Module\Block\Adminhtml\Widget\Grid\Column\Renderer\Action',

In the specified renderer class, you can implement the logic to display the link and handle the opening of the modal. Here's an example implementation:

<?php

namespace Vendor\Module\Block\Adminhtml\Widget\Grid\Column\Renderer;

use Magento\Backend\Block\Widget\Grid\Column\Renderer\Action as BaseAction;

class Action extends BaseAction
{
    public function render(\Magento\Framework\DataObject $row)
    {
        $productId = $row->getProductId();
        $url = $this->getUrl('catalog/product/edit', ['id' => $productId]);
        $this->getColumn()->setActions([
            [
                'caption' => __('Add Content'),
                'url' => $url,
                'field' => 'id',
                'popup' => true // Open in a modal popup
            ]
        ]);
        
        return parent::render($row);
    }
}

In this renderer class, the render() method is overridden to modify the action link and set the 'popup' key to true. This ensures that the link opens in a modal popup. Finally, the modified actions array is set back to the column before rendering it using the parent renderer.

Make sure to replace 'Vendor\Module\Block\Adminhtml\Widget\Grid\Column\Renderer\Action' with the actual class path of your renderer class.

By following these steps, the "Add Content" link in the action column should open the desired model popup with a form.

2
  • Hi @Noor Mohamed, Thanks Man now popup is appeared :) You save my days. Also you explained very well :) I have couple of questions, 1. can we open the popup like Advance inventory? 2. how to load custom form inside that popup
    – user73267
    Commented Jun 1, 2023 at 19:40
  • As I tried to pass through controller to open custom form but the form is not loaded with button data
    – user73267
    Commented Jun 1, 2023 at 19:46

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.