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,
));
Best Answer
In your
Grid
class add this method:replace
module
andcontroller
with the real values from your module.