1

I have a block that prepare a grid. enter image description here

In this render I want add a button that call to controller to export.

How I can agree this button to call one controller?

Thanks

1 Answer 1

2

Your render should be:

<?php

namespace Sistel\CouponActivity\Block\Adminhtml\Grid\Column\Renderer;

class Link extends \Magento\Backend\Block\Widget\Grid\Column\Renderer\AbstractRenderer
{
    /**
     * @var Action\UrlBuilder
     */
    protected $actionUrlBuilder;

    /**
     * @param \Magento\Backend\Block\Context $context
     * @param Action\UrlBuilder $actionUrlBuilder
     * @param array $data
     */
    public function __construct(
        \Magento\Backend\Block\Context $context,
        Action\UrlBuilder $actionUrlBuilder,
        array $data = []
    ) {
        $this->actionUrlBuilder = $actionUrlBuilder;
        parent::__construct($context, $data);
    }

    /**
     * Render action
     *
     * @param \Magento\Framework\DataObject $row
     * @return string
     */
    public function render(\Magento\Framework\DataObject $row)
    {
        $href = $this->actionUrlBuilder->getUrl(
            $row->getIdentifier()
        );
        return '<a href="' . $href . '" target="_blank">' . __('Preview') . '</a>';
    }
}

We can take a look here: vendor/magento/module-cms/Block/Adminhtml/Page/Grid.php

'renderer' => 'Magento\Cms\Block\Adminhtml\Page\Grid\Renderer\Action',

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.