1

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

enter image description here

Saravanan DS
1,1461 gold badge18 silver badges46 bronze badges
asked Nov 7, 2017 at 11:38
0

1 Answer 1

0

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

answered Nov 8, 2017 at 13:16

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.