Inline-Edit im Grid aktivieren
Inline-Edit im Grid aktivieren
~8 Min. Lesezeit Zuletzt aktualisiert am 9. August 2026
Inline-Edit erlaubt es, Zellenwerte direkt im Grid zu bearbeiten und zu speichern, ohne das Formular zu öffnen - komplett fertig eingebaut in Magento_Ui, nur eine Deklaration und ein Controller sind nötig.
editorConfig in listing.xml
<listing>
<!-- ... dataSource, columns wie in Kapitel 15 ... -->
<columns name="testimonial_columns">
<settings>
<editorConfig>
<param name="clientConfig" xsi:type="array">
<item name="saveUrl" xsi:type="url" path="mironsoft_testimonial/testimonial/inlineEdit"/>
<item name="validateBeforeSave" xsi:type="boolean">false</item>
</param>
<param name="indexField" xsi:type="string">testimonial_id</param>
<param name="enabled" xsi:type="boolean">true</param>
</editorConfig>
</settings>
<column name="customer_name">
<settings>
<filter>text</filter>
<editor>
<editorType>text</editorType>
<validation>
<rule name="required-entry" xsi:type="boolean">true</rule>
</validation>
</editor>
<label translate="true">Customer</label>
</settings>
</column>
<column name="is_active">
<settings>
<options class="Mironsoft\Testimonial\Model\Source\IsActive"/>
<filter>select</filter>
<editor>
<editorType>select</editorType>
</editor>
<dataType>select</dataType>
<label translate="true">Status</label>
</settings>
</column>
</columns>
</listing>Jede Spalte, die bearbeitbar sein soll, bekommt ein <editor>-Element mit passendem editorType (text, select, date, textarea). Spalten ohne <editor> - etwa die Actions- oder die Bild-Spalte - bleiben automatisch schreibgeschützt.
Der InlineEdit-Controller
<?php
declare(strict_types=1);
namespace Mironsoft\Testimonial\Controller\Adminhtml\Testimonial;
use Magento\Backend\App\Action;
use Magento\Backend\App\Action\Context;
use Magento\Framework\App\Action\HttpPostActionInterface;
use Magento\Framework\Controller\Result\Json;
use Magento\Framework\Controller\Result\JsonFactory;
use Mironsoft\Testimonial\Api\TestimonialRepositoryInterface;
/**
* Persists grid inline-edit changes for one or more testimonials.
*/
class InlineEdit extends Action implements HttpPostActionInterface
{
public const ADMIN_RESOURCE = 'Mironsoft_Testimonial::save';
/**
* @param Context $context Backend action context.
* @param TestimonialRepositoryInterface $testimonialRepository Loads/saves testimonials.
* @param JsonFactory $resultJsonFactory Factory for the JSON result.
*/
public function __construct(
Context $context,
private readonly TestimonialRepositoryInterface $testimonialRepository,
private readonly JsonFactory $resultJsonFactory,
) {
parent::__construct($context);
}
/**
* Applies the posted cell changes and reports per-row errors, if any.
*
* @return Json
*/
public function execute(): Json
{
$result = $this->resultJsonFactory->create();
$items = (array) $this->getRequest()->getParam('items', []);
$errorMessages = [];
if (!$items) {
return $result->setData([
'messages' => [__('Please correct the data sent.')],
'error' => true,
]);
}
foreach ($items as $itemData) {
$testimonialId = (int) ($itemData['testimonial_id'] ?? 0);
try {
$testimonial = $this->testimonialRepository->getById($testimonialId);
$testimonial->setData(array_merge($testimonial->getData(), $itemData));
$this->testimonialRepository->save($testimonial);
} catch (\Throwable $exception) {
$errorMessages[] = '[Row ID: ' . $testimonialId . '] ' . $exception->getMessage();
}
}
return $result->setData([
'messages' => $errorMessages,
'error' => (bool) $errorMessages,
]);
}
}Der Response folgt einem festen Vertrag: error (boolean) und messages (Array von Strings) - genau das erwartet die JavaScript-Editor-Komponente, um pro Zeile Fehler-Icons und Tooltips anzuzeigen.
Achtung: array_merge($testimonial->getData(), $itemData) ist hier wichtig: $itemData enthält nur die tatsächlich geänderten Felder der bearbeiteten Zeile, nicht den kompletten Datensatz. Ein direktes setData($itemData) ohne Merge würde alle nicht mitgesendeten Felder (zum Beispiel testimonial_text) mit null überschreiben.
Tipp: Inline-Edit und die Modifier aus Kapitel 13 ergänzen sich, statt zu konkurrieren: Modifier steuern das volle Formular, Inline-Edit die schnelle Änderung einzelner Felder direkt im Grid - beide greifen am Ende auf dieselbe TestimonialRepositoryInterface zu.