I am using Magento 2.1.7 version. I have created a custom admin grid module. It is listing out the grid, But I can't click row to edit action. I followed this link
Saravanan DS
1,1461 gold badge18 silver badges46 bronze badges
1 Answer 1
I fixed this issue. i added code app/code/[vendername]/[modulename]/view/adminhtml/ui_component/mohan_listing.xml
<actionsColumn name="actions" class="[vendername]\[modulename]\Ui\Component\Listing\Column\PostAction">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="indexField" xsi:type="string">id</item>
<item name="viewUrlPath" xsi:type="string">*/*/edit</item>
<item name="urlEntityParamName" xsi:type="string">id</item>
<item name="sortOrder" xsi:type="number">200</item>
</item>
</argument>
</actionsColumn>
and i create new file [vendername][modulename]\Ui\Component\Listing\Column\PostAction.php
namespace [vendername]\[modulename]\Ui\Component\Listing\Column;
use Magento\Framework\UrlInterface;
use Magento\Framework\View\Element\UiComponent\ContextInterface;
use Magento\Framework\View\Element\UiComponentFactory;
use Magento\Ui\Component\Listing\Columns\Column;
class PostAction extends Column
{
/**
* @var UrlInterface
*/
protected $urlBuilder;
/**
* Constructor
*
* @param ContextInterface $context
* @param UiComponentFactory $uiComponentFactory
* @param UrlInterface $urlBuilder
* @param array $components
* @param array $data
*/
public function __construct(
ContextInterface $context,
UiComponentFactory $uiComponentFactory,
UrlInterface $urlBuilder,
array $components = [],
array $data = []
) {
$this->urlBuilder = $urlBuilder;
parent::__construct($context, $uiComponentFactory, $components, $data);
}
/**
* Prepare Data Source
*
* @param array $dataSource
* @return array
*/
public function prepareDataSource(array $dataSource)
{
if (isset($dataSource['data']['items'])) {
foreach ($dataSource['data']['items'] as & $item) {
if (isset($item['blogpost_id'])) {
$viewUrlPath = $this->getData('config/viewUrlPath') ?: '#';
$urlEntityParamName = $this->getData('config/urlEntityParamName') ?: 'blogpost_id';
$item[$this->getData('name')] = [
'view' => [
'href' => $this->urlBuilder->getUrl(
$viewUrlPath,
[
$urlEntityParamName => $item['blogpost_id']
]
),
'label' => __('Edit')
]
];
}
}
}
return $dataSource;
}
}
It working fine
default