1

I did it:

enter image description here

system.xml

<field id="active" translate="label" sortOrder="220" showInDefault="1" showInWebsite="1" showInStore="0">
    <label>active buy</label>
    <frontend_model>[Vendor]\[Ext]\Block\System\Config\Form\Field\Active</frontend_model>
    <backend_model>Magento\Config\Model\Config\Backend\Serialized\ArraySerialized</backend_model>
</field>

active.php

....

protected function _prepareToRender() {
    $this->addColumn('col_1', ['label' => __('Column 1'),  'renderer' => false]);
    $this->addColumn('col_2', ['label' => __('Column 2'),  'renderer' => false]);

    $this->_addAfter = false;
    $this->_addButtonLabel = __('Add');
        $this->_addAfter = false;
        $this->_addButtonLabel = __('Add');
}

...

Standart field upload image. enter image description here

As instead of "Column 2" to put the "Standart field upload image"? Need that all worked successfully when you click the add button.

1 Answer 1

0

For customizing of single column rendering, you need to add renderer in column configuration.

$fileInputRenderer = $this->getLayout()->createBlock(MyFileRenderer::class);
$this->addColumn(
    'col_2',
    [
        'label' => __('Column 2'),
        'renderer' => $fileInputRenderer
    ]
);

Custom renderer must extend from \Magento\Framework\View\Element\AbstractBlock and must renderer template for column cell.

Example:

class MyFileRenderer extends \Magento\Framework\View\Element\AbstractBlock
{
    /**
     * {@inheritdoc}
     */
    protected function _toHtml()
    {
        $column = $this->getColumn();

        return '<input type="file" />';
    }
}

Note, that html rendering in PHP class is not good idea, you can use *.phtml template file for this.

3
  • Thanks. It good worked. But how upload image in media magento? Commented Jan 18, 2017 at 12:05
  • This is just another question. I think, that you need to use Ajax file uploading with js components for fill configuration values. Alternatively you can add custom plugin or observer for saving of requested images.
    – Max
    Commented Jan 21, 2017 at 14:10
  • @Max col_2 values are not save in database also. Please check this
    – HaFiz Umer
    Commented Jun 24, 2020 at 14:35

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.