3

I created a custom module.In grid if data is available then in action column edit option is there. If there is no data, then no edit option is displayed. So, I cannot enter into edit page if no data is available.
I cant use add new entry button. My requirement is to get the link in a grid column. I tried using a renderer but no luck.

namespace Vendor\Module\Block\Adminhtml\Data\Grid\Renderer;
class Link extends \Magento\Backend\Block\Widget\Grid\Column\Renderer\AbstractRenderer
{
public function render(\Magento\Framework\DataObject $row)
{
    $category = $row->getDataAllowed();
    if (empty($category))
    {
        $value =  $row->getData($this->getColumn()->getIndex());
        return '<a href="http://www.google.com">New'.$value.'</a>';
    }
}
}

and in customgrid.php I mention renderer also.

  $this->addColumn('action', array(
        'header' => __('Action'),
        'width' => '100',
        'type' => 'action',
        'getter' => 'getId',
        'renderer' => 'Vendor\Module\Block\Adminhtml\Data\Grid\Renderer\Link',
        'actions' => array(
            array(
                'caption' => __('Edit'),
                'url' => array('base' => 'vendor_module/Data/edit'),
                'field' => 'id'
            )
        ), 
        'filter' => false,
        'sortable' => false,
        'index' => 'stores',
        'is_system' => true,
    ));

The output should come like this enter image description here

1
  • using Ui components ? Or BlocK ?
    – Tushar
    Sep 6, 2018 at 17:16

1 Answer 1

0

In your Grid class add this method:

public function getEmptyText()
{
    $url = $this->getUrl('module/controller/new')
    return '<a href="'.$url.'">'.__('New record').'</a>';
}

replace module and controller with the real values from your module.

1
  • Thanks Marius but still I am not getting proper output. I edited my question by adding the image. Please help me thanks in advance.
    – Rising
    Nov 22, 2016 at 5: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.