0

I have custom grid and front end form in my module.

The form is submitted via frontend and saved in DB.

I am showing all the records in backend grid.

One of its field is file uploder field.

While submitting the form , I have save the uploded files in below folder path

**pub/media/myfolder/example.pdf**

And i also saved the path of the file in DB.

Now i wish to show the download link of the pdf file in admin grid.

Please provide me a solution how to add download link in admin grid

The below one is a resume uploder field

$this->addColumn(
            'resume', [
                'header' => __('Resume'),
                'index' => 'resume'
            ]
        );
1

To achieve this using render.

$this->addColumn(
            'resume', [
                'header' => __('Resume'),
                'index' => 'resume',
                'renderer'  => '<Vendor>\<Module>\Block\Adminhtml\Promo\Quote\Edit\Tab\Renderer\RenderName'
            ]
        );

After that Make renderer file RenderName.php

<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
namespace <vendor>\<ModuleName>\Block\Adminhtml\Promo\Quote\Edit\Tab\Renderer;

use Magento\Framework\DataObject;
use Magento\Framework\UrlInterface;
/**
 * Description of TestId
 *
 * @author dharmendra
 */
class RenderName extends \Magento\Backend\Block\Widget\Grid\Column\Renderer\AbstractRenderer
{
    /** Url Path */
    const URL_PATH = 'test/test/test';

    /**
     * @var UrlInterface
     */
    private $urlBuilder;
    public function __construct(
        UrlInterface $urlBuilder
    ) {
        $this->urlBuilder = $urlBuilder;
    }

    /**
     * get category name
     * @param  DataObject $row
     * @return string
     */
    public function render(DataObject $row)
    {
        return '<a href="' . $this->urlBuilder->getUrl(self::URL_PATH, ['id' => $row->getIdentifier()]) . '" target="_blank">' . __('Preview') . '</a>';
    }
}

After that check. You have to get link in your grid. Still you have getting any issue let me know.

Make Url as per your need.

  • But tyou have mentioned url path as static, each resuem field have different pdf files – Jaisa Sep 18 '18 at 8:37
  • You have print $row->getData() and you will get which you have need. – Dharmendra Jadav Sep 18 '18 at 9:12
  • I have just add example of url. – Dharmendra Jadav Sep 18 '18 at 9:12
  • Hi it works and shows the file preview, thank you, but i need to download the file – Jaisa Sep 18 '18 at 9:14
  • If you download the file you can have to add controller for that. – Dharmendra Jadav Sep 18 '18 at 9:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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