I want to create admin config with a table to take the data and save in config for that I followed this link.
But I also want to create custom rows in that table programmatically and also without the last action column and add button. Please refer the image
I was unable to find any solution on the web regarding the same nor the file
\Magento\Config\Block\System\Config\Form\Field\FieldArray\AbstractFieldArraythat we extend gave any clues.
Could have easily done this via jquery but want to implement the standard solution.
Code:
<?php
namespace Abc\Paymentmethod\Block\Adminhtml\System\Config\Form\Field;
class Feetable extends \Magento\Config\Block\System\Config\Form\Field\FieldArray\AbstractFieldArray
{
/**
* @var \Magento\Framework\Data\Form\Element\Factory
*/
protected $_elementFactory;
/**
* @param \Magento\Backend\Block\Template\Context $context
* @param \Magento\Framework\Data\Form\Element\Factory $elementFactory
* @param array $data
*/
public function __construct(
\Magento\Backend\Block\Template\Context $context,
\Magento\Framework\Data\Form\Element\Factory $elementFactory,
array $data = []
)
{
$this->_elementFactory = $elementFactory;
parent::__construct($context,$data);
}
protected function _construct(){
$this->addColumn('noi', ['label' => __('NOI'),'readonly'=>'readonly']);
$this->addColumn('fixed', ['label' => __('Fixed')]);
$this->addColumn('percent', ['label' => __('Percent')]);
$this->_addAfter = false;
$this->_addButtonLabel = __('Add More');
parent::_construct();
}
protected function _prepareArrayRow(\Magento\Framework\DataObject $row) {
$options = [1,2,3];
$row->setData('option_extra_attrs', $options);
}
}
system.xml
<field id="abc_fee_table" translate="label comment tooltip" sortOrder="17.4" showInDefault="1" showInWebsite="1" showInStore="0">
<label>Abc Fee by Number of Installments(NOI)</label>
<frontend_model>Abc\Paymentmethod\Block\Adminhtml\System\Config\Form\Field\Feetable</frontend_model>
<backend_model>Magento\Config\Model\Config\Backend\Serialized\ArraySerialized</backend_model>
</field>