0

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

0

@mohan please try this , it will work definitely https://webkul.com/blog/create-grid-edit-add-grid-row-and-installer-in-magento2/

|improve this answer|||||
  • I am using ui-component method. – mohan Nov 7 '17 at 11:45
  • i try this link also getting some other issues – mohan Nov 7 '17 at 12:25
  • @mohan could you please let me know which error you are facing – Navin Bhudiya Nov 8 '17 at 7:59
  • it working fine . – mohan Nov 8 '17 at 13:05
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

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.