1

I create admin ui grid and i want to add functionality of inline editable grid. But, it's not working for me.

This is my vendor_module_test_listing.xml file code:

<item name="editorConfig" xsi:type="array">
    <item name="selectProvider" xsi:type="string">vendor_module_test_listing.vendor_module_test_listing.vendor_module_test_columns.ids</item>
    <item name="enabled" xsi:type="boolean">false</item>
    <item name="indexField" xsi:type="string">entity_id</item>
    <item name="clientConfig" xsi:type="array">
        <item name="saveUrl" xsi:type="url" path="*/*/inlineEdit"/>
        <item name="validateBeforeSave" xsi:type="boolean">false</item>
    </item>
</item>

What I missing or do any mistake?

Please help me.

Thanks.

1 Answer 1

2

Your <item name="enabled"> value is false. First of all, set true value as like below :

vendor_module_test_listing.xml :

<item name="editorConfig" xsi:type="array">
    <item name="selectProvider" xsi:type="string">vendor_module_test_listing.vendor_module_test_listing.vendor_module_test_columns.ids</item>
    <item name="enabled" xsi:type="boolean">true</item>
    <item name="indexField" xsi:type="string">entity_id</item>
    <item name="clientConfig" xsi:type="array">
        <item name="saveUrl" xsi:type="url" path="*/*/inlineEdit"/>
        <item name="validateBeforeSave" xsi:type="boolean">false</item>
    </item>
</item>

Also, add this below code for clickable grid by field :

<item name="childDefaults" xsi:type="array">
  <item name="fieldAction" xsi:type="array">
    <item name="provider" xsi:type="string">vendor_module_test_listing.vendor_module_test_listing.vendor_module_test_columns_editor</item>
    <item name="target" xsi:type="string">startEdit</item>
    <item name="params" xsi:type="array">
      <item name="0" xsi:type="string">${ $.$data.rowIndex }</item>
      <item name="1" xsi:type="boolean">true</item>
    </item>
  </item>
</item>

Now, create controller file app\code\Vendor\Module\Controller\Adminhtml\Test\inlineEdit.php :

<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

namespace Vendor\Module\Controller\Adminhtml\Test;

use Magento\Backend\App\Action;
use Magento\Backend\App\Action\Context;
use Magento\Framework\Controller\Result\JsonFactory;
use Vendor\Module\Model\ResourceModel\Test\Collection;

/**
 * Grid inline edit controller file
 *
 * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
 */
class InlineEdit extends Action
{
    /**
     * @var JsonFactory
     */
    protected $jsonFactory;

    /**
     * @var Collection
     */
    protected $testCollection;

    /**
     * [__construct description]
     * @param Context     $context        [description]
     * @param Collection  $testCollection [description]
     * @param JsonFactory $jsonFactory    [description]
     */
    public function __construct(
        Context $context,
        Collection $testCollection,
        JsonFactory $jsonFactory
    ) {
        parent::__construct($context);
        $this->jsonFactory = $jsonFactory;
        $this->testCollection = $testCollection;
    }

    /**
     * @return \Magento\Framework\Controller\ResultInterface
     */
    public function execute()
    {
        /** @var \Magento\Framework\Controller\Result\Json $resultJson */
        $resultJson = $this->jsonFactory->create();
        $error = false;
        $messages = [];

        $postItems = $this->getRequest()->getParam('items', []);
        if (!($this->getRequest()->getParam('isAjax') && count($postItems))) {
            return $resultJson->setData([
                'messages' => [__('Please correct the data sent.')],
                'error' => true,
            ]);
        }

        try {
            $this->testCollection
                ->setStoreId($this->getRequest()->getParam('store', 0))
                ->addFieldToFilter('entity_id', ['in' => array_keys($postItems)])
                ->walk('saveCollection', [$postItems]);
        } catch (\Exception $e) {
            $messages[] = __('There was an error saving the data: ') . $e->getMessage();
            $error = true;
        }

        return $resultJson->setData([
            'messages' => $messages,
            'error' => $error,
        ]);
    }
}

Now, update your column code as like below way :

<column name="title">
    <argument name="data" xsi:type="array">
        <item name="config" xsi:type="array">
            <!-- inlineEdit code -->
            <item name="editor" xsi:type="array">
                <item name="editorType" xsi:type="string">text</item>
                    <item name="validation" xsi:type="array">
                    <item name="required-entry" xsi:type="boolean">true</item>
                    <item name="validate-zero-or-greater" xsi:type="boolean">true</item>
                </item>
            </item>
           <!-- End inlineEdit code -->
            <item name="filter" xsi:type="string">text</item>
            <item name="label" xsi:type="string" translate="true">Title</item>
            <item name="sortOrder" xsi:type="number">30</item>
        </item>
    </argument>
</column>

<item name="editor" xsi:type="array"> .. </item> is useful for make editable field.

Check this all requirements in your module.

Hope, it will helpful for you.

1
  • Happy to help ..!! Happy coding :) Commented Mar 7, 2019 at 17:23

Your Answer

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

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