I have created admin grit using ui component. I'm trying to implement grid actions.the grid lists out my form details. how add view action to the grid
app/code/Dyode/Pricebeat/Controller/Adminhtml/Form/View.php
<?php
namespace Dyode\Pricebeat\Controller\Adminhtml\Form;
class View extends \Dyode\Pricebeat\Controller\Adminhtml\Form
{
/**
* Backend session
*
* @var \Magento\Backend\Model\Session
*/
protected $backendSession;
/**
* Page factory
*
* @var \Magento\Framework\View\Result\PageFactory
*/
protected $resultPageFactory;
/**
* Result JSON factory
*
* @var \Magento\Framework\Controller\Result\JsonFactory
*/
protected $resultJsonFactory;
/**
* constructor
*
* @param \Magento\Backend\Model\Session $backendSession
* @param \Magento\Framework\View\Result\PageFactory $resultPageFactory
* @param \Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory
* @param \Dyode\Pricebeat\Model\FormFactory $formFactory
* @param \Magento\Framework\Registry $registry
* @param \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory
* @param \Magento\Backend\App\Action\Context $context
*/
public function __construct(
\Magento\Backend\Model\Session $backendSession,
\Magento\Framework\View\Result\PageFactory $resultPageFactory,
\Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory,
\Dyode\Pricebeat\Model\FormFactory $formFactory,
\Magento\Framework\Registry $registry,
\Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory,
\Magento\Backend\App\Action\Context $context
)
{
$this->backendSession = $backendSession;
$this->resultPageFactory = $resultPageFactory;
$this->resultJsonFactory = $resultJsonFactory;
parent::__construct($formFactory, $registry, $resultRedirectFactory, $context);
}
/**
* is action allowed
*
* @return bool
*/
protected function _isAllowed()
{
return $this->_authorization->isAllowed('Dyode_Pricebeat::form');
}
/**
* @return \Magento\Backend\Model\View\Result\Page|\Magento\Backend\Model\View\Result\Redirect|\Magento\Framework\View\Result\Page
*/
public function execute()
{
$id = $this->getRequest()->getParam('form_id');
/** @var \Dyode\Pricebeat\Model\Form $form */
$form = $this->initForm();
/** @var \Magento\Backend\Model\View\Result\Page|\Magento\Framework\View\Result\Page $resultPage */
$resultPage = $this->resultPageFactory->create();
$resultPage->setActiveMenu('Dyode_Pricebeat::form');
$resultPage->getConfig()->getTitle()->set(__('Pricebeat'));
if ($id) {
$form->load($id);
if (!$form->getId()) {
$this->messageManager->addError(__('This form no longer exists.'));
$resultRedirect = $this->resultRedirectFactory->create();
$resultRedirect->setPath(
'dyode_pricebeat/*/view',
[
'form_id' => $form->getId(),
'_current' => true
]
);
return $resultRedirect;
}
}
$title = $form->getId() ? $form->getTitle() : __('Pricebeat');
$resultPage->getConfig()->getTitle()->prepend($title);
$data = $this->backendSession->getData('dyode_dyode_form_data', true);
if (!empty($data)) {
$form->setData($data);
}
return $resultPage;
}
}
app/code/Dyode/Pricebeat/view/adminhtml/layout/dyode_pricebeat_form_view.xml
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="admin-2columns-left" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_configuration.xsd">
<body>
<referenceContainer name="content">
<block class="Dyode\Pricebeat\Block\Adminhtml\Form\Edit" name="dyode_pricebeat_form_view"/>
</referenceContainer>
<referenceContainer name="left">
<block class="Dyode\Pricebeat\Block\Adminhtml\Form\Edit\Tabs" name="dyode_pricebeat_form_tabs">
<block class="Dyode\Pricebeat\Block\Adminhtml\Form\Edit\Tab\Form" name="dyode_pricebeat_form_edit_tab_form"/>
<action method="addTab">
<argument name="name" xsi:type="string">form</argument>
<argument name="block" xsi:type="string">dyode_pricebeat_form_view_tab_form</argument>
</action>
</block>
</referenceContainer>
</body>
</page>
Best Answer
Please add this in your ui component File.
After that make actions file at given path \\Ui\Component\Listing\Columns\. .php
Implement this you have to get action in your ui based grid.
Still you have any difficulty let me know.