How to add a link in a grid column if the records are not found





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







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 VendorModuleBlockAdminhtmlDataGridRenderer;
class Link extends MagentoBackendBlockWidgetGridColumnRendererAbstractRenderer
{
public function render(MagentoFrameworkDataObject $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' => 'VendorModuleBlockAdminhtmlDataGridRendererLink',
'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










share|improve this question
















bumped to the homepage by Community yesterday


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
















  • using Ui components ? Or BlocK ?

    – Tushar
    Sep 6 '18 at 17:16


















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 VendorModuleBlockAdminhtmlDataGridRenderer;
class Link extends MagentoBackendBlockWidgetGridColumnRendererAbstractRenderer
{
public function render(MagentoFrameworkDataObject $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' => 'VendorModuleBlockAdminhtmlDataGridRendererLink',
'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










share|improve this question
















bumped to the homepage by Community yesterday


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
















  • using Ui components ? Or BlocK ?

    – Tushar
    Sep 6 '18 at 17:16














3












3








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 VendorModuleBlockAdminhtmlDataGridRenderer;
class Link extends MagentoBackendBlockWidgetGridColumnRendererAbstractRenderer
{
public function render(MagentoFrameworkDataObject $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' => 'VendorModuleBlockAdminhtmlDataGridRendererLink',
'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










share|improve this question
















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 VendorModuleBlockAdminhtmlDataGridRenderer;
class Link extends MagentoBackendBlockWidgetGridColumnRendererAbstractRenderer
{
public function render(MagentoFrameworkDataObject $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' => 'VendorModuleBlockAdminhtmlDataGridRendererLink',
'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







magento2 magento-2.0 magento-2.0.7






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 22 '16 at 5:32







Rising

















asked Nov 21 '16 at 12:55









RisingRising

313




313





bumped to the homepage by Community yesterday


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.







bumped to the homepage by Community yesterday


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.















  • using Ui components ? Or BlocK ?

    – Tushar
    Sep 6 '18 at 17:16



















  • using Ui components ? Or BlocK ?

    – Tushar
    Sep 6 '18 at 17:16

















using Ui components ? Or BlocK ?

– Tushar
Sep 6 '18 at 17:16





using Ui components ? Or BlocK ?

– Tushar
Sep 6 '18 at 17:16










1 Answer
1






active

oldest

votes


















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.






share|improve this answer
























  • 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 '16 at 5:33












Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "479"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f146754%2fhow-to-add-a-link-in-a-grid-column-if-the-records-are-not-found%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









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.






share|improve this answer
























  • 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 '16 at 5:33
















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.






share|improve this answer
























  • 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 '16 at 5:33














0












0








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.






share|improve this answer













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.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 21 '16 at 13:40









MariusMarius

168k28323689




168k28323689













  • 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 '16 at 5:33



















  • 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 '16 at 5:33

















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 '16 at 5:33





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 '16 at 5:33


















draft saved

draft discarded




















































Thanks for contributing an answer to Magento Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f146754%2fhow-to-add-a-link-in-a-grid-column-if-the-records-are-not-found%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

What other Star Trek series did the main TNG cast show up in?

Berlina muro

Berlina aerponto